-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
339 lines (285 loc) · 12.1 KB
/
tests.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
from unittest import TestCase
import download_data
import filter_codenames
import src.analyzing_utils
import src.data_utils
import src.download_utils
import src.filtering_utils
import src.item_data_utils as itemdata
import src.metadata_utils as meta
import src.summarizing_utils
class TestItemDataUtilsMethods(TestCase):
def test_get_item_data_filename(self):
item_id = "60e58164ca7442d78c39f5ba54ff2e63"
fname = itemdata.get_item_data_filename(item_id)
expected_fname = f"data/items/{item_id}.json"
self.assertEqual(fname, expected_fname)
def test_load_item_data(self):
item_id = "60e58164ca7442d78c39f5ba54ff2e63"
item_data = itemdata.load_item_data(item_id)
self.assertGreater(len(item_data), 0)
item_id = "dummy"
item_data = itemdata.load_item_data(item_id)
self.assertIsNone(item_data)
class TestDataUtilsMethods(TestCase):
def test_get_data_types(self):
data_types = src.data_utils.get_data_types()
self.assertEqual(len(data_types), 2)
self.assertIn("items", data_types)
self.assertIn("offers", data_types)
def test_get_data_file_name(self):
data_types = src.data_utils.get_data_types()
for data_type in data_types:
fname = src.data_utils.get_data_file_name(data_type)
expected_fname = f"data/{data_type}_list.json"
self.assertEqual(fname, expected_fname)
def test_load_data(self):
data = src.data_utils.load_data()
self.assertGreater(len(data), 0)
def test_save_data(self):
dummy_output = {"test": 123}
dummy_fname = "temp.json"
flag = src.data_utils.save_data(dummy_output, dummy_fname)
self.assertTrue(flag)
class TestMetaDataUtilsMethods(TestCase):
def test_parse_metadata_from_items(self):
data_element = [
"12160a20dbb645d7a3672959b5d7ed03",
"phlox",
"Griftlands",
["games", "applications"],
"Klei Entertainment",
1551704831,
1618503565,
]
metadata = meta.parse_metadata(data_element)
self.assertEqual(len(metadata), 9)
def test_parse_metadata_from_offers(self):
data_element = [
"3299949f391a4dbb9e0c4b28b683992c",
"phlox",
"Griftlands",
["games", "games/edition/base", "games/edition", "applications"],
"Klei Entertainment",
1551705084,
1618503526,
"https://cdn1.epicgames.com/phlox/offer/EGS_Griftlands_KleiEntertainment_S2-860x1148-5fc47bd45ab3e9271046563fa33b5081.jpg",
"griftlands/home",
]
metadata = meta.parse_metadata(data_element)
self.assertEqual(len(metadata), 9)
def test_is_of_interest(self):
metadata = {
"title": "PythonAudience",
"author": "Tim Sweeney",
"category": ["games", "NOTaddons"],
}
self.assertTrue(meta.is_of_interest(metadata))
metadata = {
"title": "PythonStaging",
"author": "Tim Sweeney",
"category": ["games", "NOTaddons"],
}
self.assertTrue(meta.is_of_interest(metadata))
metadata = {
"title": "PythonGeneralAudience",
"author": "Tim Sweeney",
"category": ["games", "NOTaddons"],
}
self.assertFalse(meta.is_of_interest(metadata))
metadata = {
"title": "PythonGeneralAudienceStaging",
"author": "Tim Sweeney",
"category": ["games", "NOTaddons"],
}
self.assertFalse(meta.is_of_interest(metadata))
metadata = {
"title": "Python",
"author": "Tim Sweeney",
"category": ["games", "NOTaddons"],
}
self.assertFalse(meta.is_of_interest(metadata))
metadata = {
"title": "PythonAudience",
"author": "Tim Sweeney",
"category": ["games", "addons"],
}
self.assertFalse(meta.is_of_interest(metadata))
metadata = {
"title": "PythonAudience",
"author": "",
"category": ["games", "NOTaddons"],
}
self.assertFalse(meta.is_of_interest(metadata))
def test_has_store_page(self):
metadata = {"image": "123", "slug": "456"}
self.assertTrue(meta.has_store_page(metadata))
metadata = {"image": "123", "slug": ""}
self.assertFalse(meta.has_store_page(metadata))
metadata = {"image": "", "slug": "456"}
self.assertFalse(meta.has_store_page(metadata))
metadata = {"image": "", "slug": ""}
self.assertFalse(meta.has_store_page(metadata))
class TestFilteringUtilsMethods(TestCase):
def test_get_namespaces_with_known_store_pages(self):
data = src.data_utils.load_data()
known_namespaces = src.filtering_utils.get_namespaces_with_known_store_pages(
data
)
self.assertGreater(len(known_namespaces), 0)
def test_filter_data(self):
data = src.data_utils.load_data()
known_namespaces = src.filtering_utils.get_namespaces_with_known_store_pages(
data
)
filtered_data = src.filtering_utils.filter_data(
data, known_namespaces, verbose=True
)
self.assertGreater(len(filtered_data), 0)
class TestSummarizingUtilsMethods(TestCase):
def test_get_prefixes(self):
prefixes = src.summarizing_utils.get_prefixes()
self.assertEqual(len(prefixes), 1)
self.assertIn("Dev", prefixes)
def test_get_suffixes(self):
suffixes = src.summarizing_utils.get_suffixes()
self.assertEqual(len(suffixes), 3)
self.assertEqual(["Audience", "Staging", "Dev"], suffixes) # the order matters!
def test_extract_codename(self):
codename = "Python"
for prefixe in ["", "Dev"]:
for suffixe in [
"",
"Audience",
"Staging",
"StagingAudience",
"Dev",
"DevAudience",
"DevStaging",
"DevStagingAudience",
]:
self.assertEqual(
src.summarizing_utils.extract_codename(
f"{prefixe}{codename}{suffixe}"
),
codename,
)
def test_summarize(self):
data = src.data_utils.load_data()
known_namespaces = src.filtering_utils.get_namespaces_with_known_store_pages(
data
)
filtered_data = src.filtering_utils.filter_data(
data, known_namespaces, verbose=False
)
sorted_devs = src.summarizing_utils.summarize(filtered_data, verbose=True)
self.assertGreater(len(sorted_devs), 0)
class TestAnalyzingUtilsMethods(TestCase):
def test_fill_in_namespaces(self):
data = src.data_utils.load_data()
known_namespaces = src.filtering_utils.get_namespaces_with_known_store_pages(
data
)
filtered_data = src.filtering_utils.filter_data(data, known_namespaces)
sorted_devs = src.summarizing_utils.summarize(filtered_data)
namespaces = src.analyzing_utils.fill_in_namespaces(
data, sorted_devs, verbose=True
)
self.assertGreater(len(namespaces), 0)
def test_is_dummy_slug(self):
self.assertTrue(src.analyzing_utils.is_dummy_slug(""))
self.assertTrue(src.analyzing_utils.is_dummy_slug("[]"))
self.assertFalse(src.analyzing_utils.is_dummy_slug("fortnite"))
def test_get_slug_suffixe_for_display(self):
suffixe = src.analyzing_utils.get_slug_suffixe_for_display({"slug": ""})
self.assertEqual(len(suffixe), 0)
suffixe = src.analyzing_utils.get_slug_suffixe_for_display({"slug": "[]"})
self.assertEqual(len(suffixe), 0)
suffixe = src.analyzing_utils.get_slug_suffixe_for_display({"slug": "fortnite"})
self.assertGreater(len(suffixe), 0)
def test_is_dummy_image_url(self):
self.assertTrue(src.analyzing_utils.is_dummy_image_url(""))
self.assertTrue(src.analyzing_utils.is_dummy_image_url("fake_url"))
self.assertFalse(src.analyzing_utils.is_dummy_image_url("http"))
self.assertFalse(src.analyzing_utils.is_dummy_image_url("https"))
def test_get_image_url_suffixe_for_display(self):
suffixe = src.analyzing_utils.get_image_url_suffixe_for_display({"image": ""})
self.assertEqual(len(suffixe), 0)
suffixe = src.analyzing_utils.get_image_url_suffixe_for_display(
{"image": "fake_url"}
)
self.assertEqual(len(suffixe), 0)
suffixe = src.analyzing_utils.get_image_url_suffixe_for_display(
{"image": "http"}
)
self.assertGreater(len(suffixe), 0)
suffixe = src.analyzing_utils.get_image_url_suffixe_for_display(
{"image": "https"}
)
self.assertGreater(len(suffixe), 0)
def test_is_dummy_save_folder(self):
self.assertTrue(src.analyzing_utils.is_dummy_save_folder(None))
self.assertTrue(src.analyzing_utils.is_dummy_save_folder(""))
self.assertFalse(
src.analyzing_utils.is_dummy_save_folder(
"{UserDir}/My Games/FINAL FANTASY VII REMAKE/"
)
)
def test_get_save_folder_suffixe_for_display(self):
item_data = None
suffixe = src.analyzing_utils.get_save_folder_suffixe_for_display(item_data)
self.assertEqual(len(suffixe), 0)
item_data = {"customAttributes": {"CloudSaveFolder": {"dummy": ""}}}
suffixe = src.analyzing_utils.get_save_folder_suffixe_for_display(item_data)
self.assertEqual(len(suffixe), 0)
item_data = {"customAttributes": {"CloudSaveFolder": {"value": ""}}}
suffixe = src.analyzing_utils.get_save_folder_suffixe_for_display(item_data)
self.assertEqual(len(suffixe), 0)
item_data = {
"customAttributes": {"CloudSaveFolder": {"value": "{UserDir}/My Games/"}}
}
suffixe = src.analyzing_utils.get_save_folder_suffixe_for_display(item_data)
self.assertGreater(len(suffixe), 0)
def test_gather_relevant_titles(self):
data = src.data_utils.load_data()
known_namespaces = src.filtering_utils.get_namespaces_with_known_store_pages(
data
)
filtered_data = src.filtering_utils.filter_data(data, known_namespaces)
sorted_devs = src.summarizing_utils.summarize(filtered_data)
namespaces = src.analyzing_utils.fill_in_namespaces(data, sorted_devs)
relevant_titles = src.analyzing_utils.gather_relevant_titles(
data, sorted_devs, namespaces, verbose=True
)
self.assertGreater(len(relevant_titles), 0)
class TestDownloadUtilsMethods(TestCase):
def test_get_data_tracker_url(self):
url = src.download_utils.get_data_tracker_url(data_type="dummy")
self.assertTrue(url.startswith("https://raw.githubusercontent.com/srdrabx/"))
self.assertTrue(url.endswith("-tracker/master/database/list.json"))
def test_get_item_data_tracker_url(self):
url = src.download_utils.get_item_data_tracker_url(item_id="dummy")
self.assertTrue(
url.startswith(
"https://raw.githubusercontent.com/srdrabx/items-tracker/master/database/items/"
)
)
self.assertTrue(url.endswith(".json"))
def test_download_from_data_tracker(self):
data = src.download_utils.download_from_data_tracker(data_type="dummy")
self.assertTrue(data is None)
def test_download_from_item_data_tracker(self):
data = src.download_utils.download_from_item_data_tracker(item_id="dummy")
self.assertIsNone(data)
data = src.download_utils.download_from_item_data_tracker(
item_id="60e58164ca7442d78c39f5ba54ff2e63"
)
self.assertIsNotNone(data)
class TestDownloadDataMethods(TestCase):
def test_main(self):
flag = download_data.main()
self.assertTrue(flag)
class TestFilterCodenamesMethods(TestCase):
def test_main(self):
flag = filter_codenames.main(request_item_data=False)
self.assertTrue(flag)