This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_show.py
361 lines (328 loc) · 16 KB
/
test_show.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2019 Linh Pham
# wwdtm is relased under the terms of the Apache License 2.0
"""Testing module for wwdtm.show"""
import json
import mysql.connector
from wwdtm.show import details, info, utility
def test_id_exists(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing repsonse from utility.id_exists"""
response = utility.id_exists(show_id, database_connection)
assert response
if print_response:
print(json.dumps(response, indent=2))
def test_id_not_exists(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing repsonse from utility.id_exists with an invalid ID"""
response = utility.id_exists(show_id, database_connection)
assert not response
if print_response:
print(json.dumps(response, indent=2))
def test_date_exists(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from utility.date_exists"""
response = utility.date_exists(show_year,
show_month,
show_day,
database_connection)
assert response
if print_response:
print(json.dumps(response, indent=2))
def test_date_not_exists(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from utility.date_exists with an incorrect date"""
response = utility.date_exists(show_year,
show_month,
show_day,
database_connection)
assert not response
if print_response:
print(json.dumps(response, indent=2))
def test_retrieve_by_id(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_id"""
show_info = info.retrieve_by_id(show_id, database_connection)
assert show_info is not None
assert "best_of" in show_info
assert "repeat_show" in show_info
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_by_invalid_id(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_id with an invalid ID"""
show_info = info.retrieve_by_id(show_id, database_connection)
assert show_info is None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_by_date(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_date"""
show_info = info.retrieve_by_date(show_year,
show_month,
show_day,
database_connection)
assert show_info is not None
assert "best_of" in show_info
assert "repeat_show" in show_info
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_by_invalid_date(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_date with incorrect date"""
try:
show_info = info.retrieve_by_date(show_year,
show_month,
show_day,
database_connection)
assert show_info is None
if print_response:
print(json.dumps(show_info, indent=2))
except ValueError:
assert True
def test_retrieve_by_date_string(show_date: str,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_date_string"""
show_info = info.retrieve_by_date_string(show_date, database_connection)
assert show_info is not None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_by_invalid_date_string(show_date: str,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_by_date_string with an
incorrect date"""
try:
show_info = info.retrieve_by_date_string(show_date, database_connection)
assert show_info is None
if print_response:
print(json.dumps(show_info, indent=2))
except ValueError:
assert True
def test_retrieve_months_by_year(show_year: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_months_by_year"""
show_months = info.retrieve_months_by_year(show_year,
database_connection)
assert show_months is not None
if print_response:
print(json.dumps(show_months, indent=2))
def test_retrieve_years(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_years"""
show_years = info.retrieve_years(database_connection)
assert show_years is not None
if print_response:
print(json.dumps(show_years, indent=2))
def test_retrieve_by_year(show_year: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response form info.retrieve_by_year"""
show_info = info.retrieve_by_year(show_year, database_connection)
assert show_info is not None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_by_year_month(show_year: int,
show_month: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response form info.retrieve_by_year_month"""
show_info = info.retrieve_by_year_month(show_year,
show_month,
database_connection)
assert show_info is not None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_all(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all"""
show_info = info.retrieve_all(database_connection)
assert show_info is not None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_all_ids(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all_ids"""
show_ids = info.retrieve_all_ids(database_connection)
assert show_ids is not None
if print_response:
print(json.dumps(show_ids, indent=2))
def test_retrieve_all_dates(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all_dates"""
show_dates = info.retrieve_all_dates(database_connection)
assert show_dates is not None
if print_response:
print(json.dumps(show_dates, indent=2))
def test_retrieve_all_dates_tuple(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all_dates_tuple"""
show_dates = info.retrieve_all_dates_tuple(database_connection)
assert show_dates is not None
if print_response:
print(json.dumps(show_dates, indent=2))
def test_retrieve_scores_by_year(show_year: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_scores_by_year"""
show_scores = info.retrieve_scores_by_year(show_year, database_connection)
assert show_scores is not None
if print_response:
print(json.dumps(show_scores, indent=2))
def test_retrieve_all_years_months(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all_show_years_months"""
show_years_months = info.retrieve_all_show_years_months(database_connection)
assert show_years_months is not None
if print_response:
print(json.dumps(show_years_months, indent=2))
def test_retrieve_all_years_months_tuple(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_all_show_years_months_tuple"""
show_years_months = info.retrieve_all_show_years_months_tuple(database_connection)
assert show_years_months is not None
if print_response:
print(json.dumps(show_years_months, indent=2))
def test_retrieve_recent(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from info.retrieve_recent"""
show_info = info.retrieve_recent(database_connection)
assert show_info is not None
if print_response:
print(json.dumps(show_info, indent=2))
def test_retrieve_details_by_id(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_id"""
show_details = details.retrieve_by_id(show_id, database_connection)
assert show_details is not None
assert "host" in show_details
assert "scorekeeper" in show_details
assert "panelists" in show_details
assert "bluff" in show_details
assert "guests" in show_details
assert "description" in show_details
assert "notes" in show_details
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_invalid_id(show_id: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_id with an
invalid ID"""
show_details = details.retrieve_by_id(show_id, database_connection)
assert show_details is None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_date(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_date"""
show_details = details.retrieve_by_date(show_year,
show_month,
show_day,
database_connection)
assert show_details is not None
assert "host" in show_details
assert "scorekeeper" in show_details
assert "panelists" in show_details
assert "bluff" in show_details
assert "guests" in show_details
assert "description" in show_details
assert "notes" in show_details
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_invalid_date(show_year: int,
show_month: int,
show_day: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing repsonse from details.retrieve_by_date with an incorrect
date"""
show_details = details.retrieve_by_date(show_year,
show_month,
show_day,
database_connection)
assert show_details is None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_date_string(show_date: str,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing repsonse from details.retrieve_by_date_string"""
show_details = details.retrieve_by_date_string(show_date,
database_connection)
assert show_details is not None
assert "host" in show_details
assert "scorekeeper" in show_details
assert "panelists" in show_details
assert "bluff" in show_details
assert "guests" in show_details
assert "description" in show_details
assert "notes" in show_details
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_invalid_date_string(show_date: str,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_date_string with
invalud date string"""
show_details = details.retrieve_by_date_string(show_date,
database_connection)
assert show_details is None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_year(show_year: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_year"""
show_details = details.retrieve_by_year(show_year,
database_connection)
assert show_details is not None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_details_by_year_month(show_year: int,
show_month: int,
database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_by_year_month"""
show_details = details.retrieve_by_year_month(show_year,
show_month,
database_connection)
assert show_details is not None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_all_details(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_all"""
show_details = details.retrieve_all(database_connection)
assert show_details is not None
if print_response:
print(json.dumps(show_details, indent=2))
def test_retrieve_recent_details(database_connection: mysql.connector.connect,
print_response: bool = False):
"""Testing response from details.retrieve_recent"""
show_details = details.retrieve_recent(database_connection)
assert show_details is not None
if print_response:
print(json.dumps(show_details, indent=2))