-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathscraper_test.py
More file actions
66 lines (55 loc) · 2.31 KB
/
scraper_test.py
File metadata and controls
66 lines (55 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from itunes_app_scraper.scraper import AppStoreScraper
from itunes_app_scraper.util import AppStoreException, AppStoreCollections, AppStoreCategories, AppStoreUtils
import json
import pytest
import os
def test_term_no_exception():
scraper = AppStoreScraper()
results = scraper.get_app_ids_for_query("mindful", country="gb", lang="en")
assert len(results) > 0
def test_no_term_gives_exception():
scraper = AppStoreScraper()
with pytest.raises(AppStoreException, match = "No term was given"):
scraper.get_app_ids_for_query("", country="gb", lang="en")
def test_no_invalid_id_gives_exception():
scraper = AppStoreScraper()
with pytest.raises(AppStoreException, match = "No app found with ID 872"):
scraper.get_app_details('872')
def test_no_invalid_id_in_multiple_is_empty():
scraper = AppStoreScraper()
assert len(list(scraper.get_multiple_app_details(['872']))) == 0
def test_no_invalid_id_in_multiple_writes_log():
scraper = AppStoreScraper()
scraper.get_multiple_app_details(['872'])
assert os.path.exists("log/nl_log.txt")
fh = open('log/nl_log.txt')
assert "No app found with ID 872" in fh.read()
fh.close()
def test_log_file_write_message():
scraper = AppStoreScraper()
scraper._log_error("gb","test")
assert os.path.exists("log/gb_log.txt")
fh = open('log/gb_log.txt')
assert "test" in fh.read()
fh.close()
def test_country_code_does_exist():
scraper = AppStoreScraper()
assert scraper.get_store_id_for_country('gb') == 143444
def test_country_code_does_not_exist():
scraper = AppStoreScraper()
with pytest.raises(AppStoreException, match="Country code not found for XZ"):
scraper.get_store_id_for_country('xz')
def test_query_multiple_pages():
query = "game"
scraper = AppStoreScraper()
results = set()
for page in range(1,4):
page_results = scraper.get_app_ids_for_query(query, country="us", lang="en", page=page)
if page_results:
[results.add(x) for x in page_results]
assert len(results) > (page-1)*50
print(f"Total results for query {query}: {len(results)}")
def test_get_app_ids_for_collection():
scraper = AppStoreScraper()
results = scraper.get_app_ids_for_collection(AppStoreCollections.TOP_FREE_IOS, country="us", lang="en")
assert len(results) > 0