-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathscraper_test.py
82 lines (70 loc) · 4.11 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from google_play_scraper.scraper import PlayStoreScraper
from google_play_scraper.util import PlayStoreException, PlayStoreCollections, PlayStoreCategories, PlayStoreUtils
import json
import pytest
import os
def test_single_app_rating_cn():
scraper = PlayStoreScraper()
app = scraper.get_app_details("com.getsomeheadspace.android", country="cn", lang="en")
assert app["rating"] > 0
def test_single_app_rating_gb():
scraper = PlayStoreScraper()
app = scraper.get_app_details("com.getsomeheadspace.android")
assert app["rating"] > 0
def test_term_no_exception():
scraper = PlayStoreScraper()
results = scraper.get_app_ids_for_query("mindful", country="gb", lang="en")
assert len(results) > 0
def test_term_less_default():
scraper = PlayStoreScraper()
results = scraper.get_app_ids_for_query("mindful", country="gb", lang="en", num=10)
assert len(results) < 50
def test_term_results_less_than_default():
scraper = PlayStoreScraper()
results = scraper.get_app_ids_for_query("tv", country="gb", lang="en")
assert len(results) == 50
def test_app_details():
# This is my app and so I have some control over the details
scraper = PlayStoreScraper()
results = scraper.get_app_details("io.github.dalewahl.carddecks", country="us", lang="en")
assert results.get('id') == 'io.github.dalewahl.carddecks'
assert results.get('title') == 'Pocket Decks: Conversation Starters, Trivia & More'
assert results.get('developer_name') == 'Dale Wahl'
assert results.get('category') == '/store/apps/category/ENTERTAINMENT' or results.get('category') == 'ENTERTAINMENT'
assert results.get('icon_link') == 'https://play-lh.googleusercontent.com/Pmjuw_wBk-Pp2XFvuCHwJbLmcuooTDE_6IobaCe4yYCAatL_88-Ivr0_zco3Wei_ooY'
assert type(results.get('num_downloads_approx')) == int
assert 100 < results.get('num_downloads') < 500
assert 100 < results.get('num_downloads') < 500
assert results.get('published_date') == 'May 4, 2020'
assert results.get('published_timestamp') == 1588615247
assert results.get('pegi') == 'Teen'
assert results.get('pegi_detail') == 'Language'
assert results.get('os') == '5.0'
assert results.get('description') == 'Download decks from the web or create your own! <br><br>This application allows you to choose a deck full of questions, conversation topics, trivia, or other games and flip through the deck. Play with friends and take turns answering questions or quiz each other.<br><br>Includes Conversation Starter games such as Never Have I Ever, Truth or Dare, Would You Rather, as well as decks of conversation topics. Trivia subjects include General Knowledge, Films, Music, Celebrities and more. Includes a deck of cards too, because why not?<br><br>Completely customizable:<br>Don't see a deck you want? Create it from scratch!<br>Don't like a card? Edit it to what you want or just delete it altogether!<br><br>Thanks to Open Trivia Database for some awesome questions!<br>https://opentdb.com/'
assert results.get('num_of_reviews') < 5
assert results.get('rating') >= 0
def test_no_term_gives_exception():
scraper = PlayStoreScraper()
with pytest.raises(PlayStoreException, match = "No term was given"):
scraper.get_app_ids_for_query("", country="gb", lang="en")
def test_no_invalid_id_gives_exception():
scraper = PlayStoreScraper()
with pytest.raises(PlayStoreException, match = "Could not parse Play Store response for 872"):
scraper.get_app_details('872')
def test_no_invalid_id_in_multiple_is_empty():
scraper = PlayStoreScraper()
assert len(list(scraper.get_multiple_app_details(['872']))) == 0
def test_no_invalid_id_in_multiple_writes_log():
scraper = PlayStoreScraper()
scraper.get_multiple_app_details(['872'])
assert os.path.exists("log/nl_log.txt")
fh = open('log/nl_log.txt')
assert "Could not parse Play Store response for 872" in fh.read()
fh.close()
def test_log_file_write_message():
scraper = PlayStoreScraper()
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()