-
Notifications
You must be signed in to change notification settings - Fork 22
/
scraper_test.py
50 lines (41 loc) · 1.71 KB
/
scraper_test.py
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
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')