| 1 | + | from mock import Mock |
| 2 | + | import pytest |
| 3 | + | |
| 4 | + | from maigret import search |
| 5 | + | |
| 6 | + | |
| 7 | + | def site_result_except(server, username, **kwargs): |
| 8 | + | query = f'id={username}' |
| 9 | + | server.expect_request('/url', query_string=query).respond_with_data(**kwargs) |
| 10 | + | |
| 11 | + | |
| 12 | + | @pytest.mark.asyncio |
| 13 | + | async def test_checking_by_status_code(httpserver, local_test_db): |
| 14 | + | sites_dict = local_test_db.sites_dict |
| 15 | + | |
| 16 | + | site_result_except(httpserver, 'claimed', status=200) |
| 17 | + | site_result_except(httpserver, 'unclaimed', status=404) |
| 18 | + | |
| 19 | + | result = await search('claimed', site_dict=sites_dict, logger=Mock()) |
| 20 | + | assert result['StatusCode']['status'].is_found() is True |
| 21 | + | |
| 22 | + | result = await search('unclaimed', site_dict=sites_dict, logger=Mock()) |
| 23 | + | assert result['StatusCode']['status'].is_found() is False |
| 24 | + | |
| 25 | + | |
| 26 | + | @pytest.mark.asyncio |
| 27 | + | async def test_checking_by_message_positive_full(httpserver, local_test_db): |
| 28 | + | sites_dict = local_test_db.sites_dict |
| 29 | + | |
| 30 | + | site_result_except(httpserver, 'claimed', response_data="user profile") |
| 31 | + | site_result_except(httpserver, 'unclaimed', response_data="404 not found") |
| 32 | + | |
| 33 | + | result = await search('claimed', site_dict=sites_dict, logger=Mock()) |
| 34 | + | assert result['Message']['status'].is_found() is True |
| 35 | + | |
| 36 | + | result = await search('unclaimed', site_dict=sites_dict, logger=Mock()) |
| 37 | + | assert result['Message']['status'].is_found() is False |
| 38 | + | |
| 39 | + | |
| 40 | + | @pytest.mark.asyncio |
| 41 | + | async def test_checking_by_message_positive_part(httpserver, local_test_db): |
| 42 | + | sites_dict = local_test_db.sites_dict |
| 43 | + | |
| 44 | + | site_result_except(httpserver, 'claimed', response_data="profile") |
| 45 | + | site_result_except(httpserver, 'unclaimed', response_data="404") |
| 46 | + | |
| 47 | + | result = await search('claimed', site_dict=sites_dict, logger=Mock()) |
| 48 | + | assert result['Message']['status'].is_found() is True |
| 49 | + | |
| 50 | + | result = await search('unclaimed', site_dict=sites_dict, logger=Mock()) |
| 51 | + | assert result['Message']['status'].is_found() is False |
| 52 | + | |
| 53 | + | |
| 54 | + | @pytest.mark.asyncio |
| 55 | + | async def test_checking_by_message_negative(httpserver, local_test_db): |
| 56 | + | sites_dict = local_test_db.sites_dict |
| 57 | + | |
| 58 | + | site_result_except(httpserver, 'claimed', response_data="") |
| 59 | + | site_result_except(httpserver, 'unclaimed', response_data="user 404") |
| 60 | + | |
| 61 | + | result = await search('claimed', site_dict=sites_dict, logger=Mock()) |
| 62 | + | assert result['Message']['status'].is_found() is False |
| 63 | + | |
| 64 | + | result = await search('unclaimed', site_dict=sites_dict, logger=Mock()) |
| 65 | + | assert result['Message']['status'].is_found() is True |
| 66 | + | |