Projects STRLCPY maigret Commits bdfb4911
🤬
  • ■ ■ ■ ■ ■ ■
    CHANGELOG.md
    skipped 1 lines
    2 2   
    3 3  ## [Unreleased]
    4 4   
     5 +## [0.2.1] - 2021-05-02
     6 +* fixed json reports generation bug, added tests
     7 + 
    5 8  ## [0.2.0] - 2021-05-02
    6 9  * added `--retries` option
    7 10  * added `source` feature for sites' mirrors
    skipped 91 lines
  • ■ ■ ■ ■
    maigret/maigret.py
    skipped 35 lines
    36 36  from .submit import submit_dialog
    37 37  from .utils import get_dict_ascii_tree
    38 38   
    39  -__version__ = '0.2.0'
     39 +__version__ = '0.2.1'
    40 40   
    41 41   
    42 42  def notify_about_errors(search_results, query_notify):
    skipped 583 lines
  • ■ ■ ■ ■ ■ ■
    maigret/report.py
    skipped 268 lines
    269 269   
    270 270   data = dict(site_result)
    271 271   data["status"] = data["status"].json()
     272 + data["site"] = data["site"].json
     273 + if "future" in data:
     274 + del data["future"]
    272 275   
    273 276   if is_report_per_line:
    274 277   data["sitename"] = sitename
    skipped 98 lines
  • ■ ■ ■ ■
    setup.py
    skipped 11 lines
    12 12   requires = rf.read().splitlines()
    13 13   
    14 14  setup(name='maigret',
    15  - version='0.2.0',
     15 + version='0.2.1',
    16 16   description='Collect a dossier on a person by username from a huge number of sites',
    17 17   long_description=long_description,
    18 18   long_description_content_type="text/markdown",
    skipped 10 lines
  • ■ ■ ■ ■ ■ ■
    tests/conftest.py
    skipped 8 lines
    9 9   
    10 10  CUR_PATH = os.path.dirname(os.path.realpath(__file__))
    11 11  JSON_FILE = os.path.join(CUR_PATH, '../maigret/resources/data.json')
     12 +TEST_JSON_FILE = os.path.join(CUR_PATH, 'db.json')
    12 13  empty_mark = Mark('', [], {})
    13 14   
    14 15   
    skipped 19 lines
    34 35  @pytest.fixture(scope='session')
    35 36  def default_db():
    36 37   db = MaigretDatabase().load_from_file(JSON_FILE)
     38 + 
     39 + return db
     40 + 
     41 + 
     42 +@pytest.fixture(scope='function')
     43 +def test_db():
     44 + db = MaigretDatabase().load_from_file(TEST_JSON_FILE)
    37 45   
    38 46   return db
    39 47   
    skipped 7 lines
  • ■ ■ ■ ■ ■ ■
    tests/db.json
     1 +{
     2 + "engines": {},
     3 + "sites": {
     4 + "GooglePlayStore": {
     5 + "tags": ["global", "us"],
     6 + "disabled": false,
     7 + "checkType": "status_code",
     8 + "alexaRank": 1,
     9 + "url": "https://play.google.com/store/apps/developer?id={username}",
     10 + "urlMain": "https://play.google.com/store",
     11 + "usernameClaimed": "Facebook_nosuchname",
     12 + "usernameUnclaimed": "noonewouldeverusethis7"
     13 + },
     14 + "Reddit": {
     15 + "tags": ["news", "social", "us"],
     16 + "checkType": "status_code",
     17 + "presenseStrs": ["totalKarma"],
     18 + "disabled": true,
     19 + "alexaRank": 17,
     20 + "url": "https://www.reddit.com/user/{username}",
     21 + "urlMain": "https://www.reddit.com/",
     22 + "usernameClaimed": "blue",
     23 + "usernameUnclaimed": "noonewouldeverusethis7"
     24 + }
     25 + }
     26 +}
  • ■ ■ ■ ■ ■ ■
    tests/test_maigret.py
    skipped 3 lines
    4 4  import pytest
    5 5  from mock import Mock
    6 6   
    7  -from maigret.maigret import self_check
    8  -from maigret.sites import MaigretDatabase
     7 +from maigret.maigret import self_check, maigret
     8 +from maigret.sites import MaigretSite
     9 +from maigret.result import QueryResult, QueryStatus
    9 10   
    10  -EXAMPLE_DB = {
    11  - 'engines': {},
    12  - 'sites': {
    13  - "GooglePlayStore": {
    14  - "tags": ["global", "us"],
    15  - "disabled": False,
    16  - "checkType": "status_code",
    17  - "alexaRank": 1,
    18  - "url": "https://play.google.com/store/apps/developer?id={username}",
    19  - "urlMain": "https://play.google.com/store",
    20  - "usernameClaimed": "Facebook_nosuchname",
    21  - "usernameUnclaimed": "noonewouldeverusethis7",
    22  - },
    23  - "Reddit": {
    24  - "tags": ["news", "social", "us"],
    25  - "checkType": "status_code",
    26  - "presenseStrs": ["totalKarma"],
    27  - "disabled": True,
    28  - "alexaRank": 17,
    29  - "url": "https://www.reddit.com/user/{username}",
    30  - "urlMain": "https://www.reddit.com/",
    31  - "usernameClaimed": "blue",
    32  - "usernameUnclaimed": "noonewouldeverusethis7",
    33  - },
    34  - },
    35  -}
     11 + 
     12 +@pytest.mark.slow
     13 +def test_self_check_db_positive_disable(test_db):
     14 + logger = Mock()
     15 + assert test_db.sites[0].disabled is False
     16 + 
     17 + loop = asyncio.get_event_loop()
     18 + loop.run_until_complete(
     19 + self_check(test_db, test_db.sites_dict, logger, silent=True)
     20 + )
     21 + 
     22 + assert test_db.sites[0].disabled is True
    36 23   
    37 24   
    38 25  @pytest.mark.slow
    39  -def test_self_check_db_positive_disable():
     26 +def test_self_check_db_positive_enable(test_db):
    40 27   logger = Mock()
    41  - db = MaigretDatabase()
    42  - db.load_from_json(EXAMPLE_DB)
    43 28   
    44  - assert db.sites[0].disabled == False
     29 + test_db.sites[0].disabled = True
     30 + test_db.sites[0].username_claimed = 'Facebook'
     31 + assert test_db.sites[0].disabled is True
    45 32   
    46 33   loop = asyncio.get_event_loop()
    47  - loop.run_until_complete(self_check(db, db.sites_dict, logger, silent=True))
     34 + loop.run_until_complete(
     35 + self_check(test_db, test_db.sites_dict, logger, silent=True)
     36 + )
    48 37   
    49  - assert db.sites[0].disabled == True
     38 + assert test_db.sites[0].disabled is False
    50 39   
    51 40   
    52 41  @pytest.mark.slow
    53  -def test_self_check_db_positive_enable():
     42 +def test_self_check_db_negative_disabled(test_db):
    54 43   logger = Mock()
    55  - db = MaigretDatabase()
    56  - db.load_from_json(EXAMPLE_DB)
    57 44   
    58  - db.sites[0].disabled = True
    59  - db.sites[0].username_claimed = 'Facebook'
    60  - assert db.sites[0].disabled == True
     45 + test_db.sites[0].disabled = True
     46 + assert test_db.sites[0].disabled is True
    61 47   
    62 48   loop = asyncio.get_event_loop()
    63  - loop.run_until_complete(self_check(db, db.sites_dict, logger, silent=True))
     49 + loop.run_until_complete(
     50 + self_check(test_db, test_db.sites_dict, logger, silent=True)
     51 + )
    64 52   
    65  - assert db.sites[0].disabled == False
     53 + assert test_db.sites[0].disabled is True
    66 54   
    67 55   
    68 56  @pytest.mark.slow
    69  -def test_self_check_db_negative_disabled():
     57 +def test_self_check_db_negative_enabled(test_db):
    70 58   logger = Mock()
    71  - db = MaigretDatabase()
    72  - db.load_from_json(EXAMPLE_DB)
    73 59   
    74  - db.sites[0].disabled = True
    75  - assert db.sites[0].disabled == True
     60 + test_db.sites[0].disabled = False
     61 + test_db.sites[0].username_claimed = 'Facebook'
     62 + assert test_db.sites[0].disabled is False
    76 63   
    77 64   loop = asyncio.get_event_loop()
    78  - loop.run_until_complete(self_check(db, db.sites_dict, logger, silent=True))
     65 + loop.run_until_complete(
     66 + self_check(test_db, test_db.sites_dict, logger, silent=True)
     67 + )
    79 68   
    80  - assert db.sites[0].disabled == True
     69 + assert test_db.sites[0].disabled is False
    81 70   
    82 71   
    83 72  @pytest.mark.slow
    84  -def test_self_check_db_negative_enabled():
     73 +def test_maigret_results(test_db):
    85 74   logger = Mock()
    86  - db = MaigretDatabase()
    87  - db.load_from_json(EXAMPLE_DB)
    88 75   
    89  - db.sites[0].disabled = False
    90  - db.sites[0].username_claimed = 'Facebook'
    91  - assert db.sites[0].disabled == False
    92  - 
     76 + username = 'Facebook'
    93 77   loop = asyncio.get_event_loop()
    94  - loop.run_until_complete(self_check(db, db.sites_dict, logger, silent=True))
     78 + results = loop.run_until_complete(
     79 + maigret(username, site_dict=test_db.sites_dict, logger=logger, timeout=30)
     80 + )
    95 81   
    96  - assert db.sites[0].disabled == False
     82 + assert isinstance(results, dict)
     83 + 
     84 + reddit_site = results['Reddit']['site']
     85 + assert isinstance(reddit_site, MaigretSite)
     86 + 
     87 + assert reddit_site.json == {
     88 + 'tags': ['news', 'social', 'us'],
     89 + 'checkType': 'status_code',
     90 + 'presenseStrs': ['totalKarma'],
     91 + 'disabled': True,
     92 + 'alexaRank': 17,
     93 + 'url': 'https://www.reddit.com/user/{username}',
     94 + 'urlMain': 'https://www.reddit.com/',
     95 + 'usernameClaimed': 'blue',
     96 + 'usernameUnclaimed': 'noonewouldeverusethis7',
     97 + }
     98 + 
     99 + del results['Reddit']['site']
     100 + del results['GooglePlayStore']['site']
     101 + 
     102 + reddit_status = results['Reddit']['status']
     103 + assert isinstance(reddit_status, QueryResult)
     104 + assert reddit_status.status == QueryStatus.ILLEGAL
     105 + 
     106 + playstore_status = results['GooglePlayStore']['status']
     107 + assert isinstance(playstore_status, QueryResult)
     108 + assert playstore_status.status == QueryStatus.CLAIMED
     109 + 
     110 + del results['Reddit']['status']
     111 + del results['GooglePlayStore']['status']
     112 + 
     113 + assert results['Reddit'].get('future') is None
     114 + del results['GooglePlayStore']['future']
     115 + 
     116 + assert results == {
     117 + 'Reddit': {
     118 + 'cookies': None,
     119 + 'parsing_enabled': False,
     120 + 'url_main': 'https://www.reddit.com/',
     121 + 'username': 'Facebook',
     122 + },
     123 + 'GooglePlayStore': {
     124 + 'cookies': None,
     125 + 'http_status': 200,
     126 + 'is_similar': False,
     127 + 'parsing_enabled': False,
     128 + 'rank': 1,
     129 + 'url_main': 'https://play.google.com/store',
     130 + 'url_user': 'https://play.google.com/store/apps/developer?id=Facebook',
     131 + 'username': 'Facebook',
     132 + },
     133 + }
    97 134   
  • ■ ■ ■ ■ ■ ■
    tests/test_report.py
    skipped 17 lines
    18 18   generate_json_report,
    19 19  )
    20 20  from maigret.result import QueryResult, QueryStatus
     21 +from maigret.sites import MaigretSite
     22 + 
     23 + 
     24 +GOOD_RESULT = QueryResult('', '', '', QueryStatus.CLAIMED)
     25 +BAD_RESULT = QueryResult('', '', '', QueryStatus.AVAILABLE)
    21 26   
    22 27  EXAMPLE_RESULTS = {
    23 28   'GitHub': {
    skipped 11 lines
    35 40   'http_status': 200,
    36 41   'is_similar': False,
    37 42   'rank': 78,
     43 + 'site': MaigretSite('test', {}),
    38 44   }
    39 45  }
    40  - 
    41  -GOOD_RESULT = QueryResult('', '', '', QueryStatus.CLAIMED)
    42  -BAD_RESULT = QueryResult('', '', '', QueryStatus.AVAILABLE)
    43 46   
    44 47  GOOD_500PX_RESULT = copy.deepcopy(GOOD_RESULT)
    45 48  GOOD_500PX_RESULT.tags = ['photo', 'us', 'global']
    skipped 301 lines
Please wait...
Page is in error, reload to recover