| 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 | | |