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.py
351 lines (271 loc) · 14.1 KB
/
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
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
# -*- coding: utf-8 -*-
# Copyright (c) 2018-2020 Linh Pham
# wwdtm is relased under the terms of the Apache License 2.0
"""Testing modules within the wwdtm package"""
import time
import json
import os
import mysql.connector
from tests import (test_guest, test_host, test_location, test_panelist,
test_scorekeeper, test_show)
def test_guest_module(database_connection: mysql.connector.connect):
"""Run tests against guest module"""
print("Testing wwdtm.guest module")
# Start Time
start_time = time.perf_counter()
# Testing guest.utility.id_exists
test_guest.test_id_exists(54, database_connection)
test_guest.test_id_not_exists(-54, database_connection)
# Testing guest.utility.slug_exists
test_guest.test_slug_exists("tom-hanks", database_connection)
test_guest.test_slug_not_exists("thom-hanks", database_connection)
# Testing retrieve all guests
test_guest.test_retrieve_all(database_connection)
test_guest.test_retrieve_all_ids(database_connection)
test_guest.test_retrieve_all_details(database_connection)
# Testing retrieve individual guest
test_guest.test_retrieve_by_id(2, database_connection)
test_guest.test_retrieve_by_slug("stephen-breyer", database_connection)
# Testing retrieve guest appearances
test_guest.test_retrieve_details_by_id(36, database_connection)
test_guest.test_retrieve_details_by_slug("tina-fey", database_connection)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def test_host_module(database_connection: mysql.connector.connect):
"""Run tests against host module"""
print("Testing wwdtm.host module")
# Start Time
start_time = time.perf_counter()
# Testing host.utility.id_exists
test_host.test_id_exists(1, database_connection)
test_host.test_id_not_exists(-1, database_connection)
# Testing host.utility.slug_exists
test_host.test_slug_exists("luke-burbank", database_connection)
test_host.test_slug_not_exists("buke-lurbank", database_connection)
# Testing retrieve all hosts
test_host.test_retrieve_all(database_connection)
test_host.test_retrieve_all_ids(database_connection)
test_host.test_retrieve_all_details(database_connection)
# Testing retrieve individual host
test_host.test_retrieve_by_id(3, database_connection)
test_host.test_retrieve_by_slug("adam-felber", database_connection)
# Testing retrieve host details
test_host.test_retrieve_details_by_id(18, database_connection)
test_host.test_retrieve_details_by_slug("faith-salie",
database_connection)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def test_location_module(database_connection: mysql.connector.connect):
"""Run tests against location module"""
print("Testing wwdtm.location module")
# Start Time
start_time = time.perf_counter()
# Testing location.utility.id_exists
test_location.test_id_exists(2, database_connection)
test_location.test_id_not_exists(-2, database_connection)
# Testing host.utility.slug_exists
test_location.test_slug_exists("chase-auditorium-chicago-il",
database_connection)
test_location.test_slug_not_exists("case-auditorium-chicago-il",
database_connection)
# Testing location.retrieve_all
test_location.test_retrieve_all(database_connection, sort_by_venue=True)
test_location.test_retrieve_all(database_connection, sort_by_venue=False)
# Testing location.retrieve_all_ids
test_location.test_retrieve_all_ids(database_connection, sort_by_venue=True)
test_location.test_retrieve_all_ids(database_connection, sort_by_venue=False)
# Testing retrieve individual location
test_location.test_retrieve_by_id(32, database_connection)
test_location.test_retrieve_by_slug("moore-theatre-seattle-wa",
database_connection)
# Testing retrieve individual location recordings
test_location.test_retrieve_recordings_by_id(32, database_connection)
test_location.test_retrieve_recordings_by_slug("moore-theatre-seattle-wa",
database_connection)
# Testing location.retrieve_all_recordings
test_location.test_retrieve_all_recordings(database_connection,
sort_by_venue=True)
test_location.test_retrieve_all_recordings(database_connection,
sort_by_venue=False)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def test_panelist_module(database_connection: mysql.connector.connect):
"""Run tests against panelist module"""
print("Testing wwdtm.panelist module")
# Start Time
start_time = time.perf_counter()
# Testing panelist.utility.id_exists
test_panelist.test_id_exists(10, database_connection)
test_panelist.test_id_not_exists(-10, database_connection)
# Testing panelist.utility.slug_exists
test_panelist.test_slug_exists("faith-salie", database_connection)
test_panelist.test_slug_not_exists("fait-sale", database_connection)
# Testing retrieve all panelists
test_panelist.test_retrieve_all(database_connection)
test_panelist.test_retrieve_all_ids(database_connection)
test_panelist.test_retrieve_all_details(database_connection)
# Testing retrieve individual panelist
test_panelist.test_retrieve_by_id(14, database_connection)
test_panelist.test_retrieve_by_slug("luke-burbank", database_connection)
# Testing retrieve panelist details
test_panelist.test_retrieve_details_by_id(2, database_connection)
test_panelist.test_retrieve_details_by_slug("tom-bodett",
database_connection)
# Testing retrieve panelist scores
test_panelist.test_retrieve_scores_grouped_list_by_id(14,
database_connection)
test_panelist.test_retrieve_scores_grouped_list_by_slug("luke-burbank",
database_connection)
test_panelist.test_retrieve_scores_grouped_ordered_pair_by_id(14,
database_connection)
test_panelist.test_retrieve_scores_grouped_ordered_pair_by_slug("luke-burbank",
database_connection)
test_panelist.test_retrieve_scores_list_by_id(30, database_connection)
test_panelist.test_retrieve_scores_list_by_slug("faith-salie",
database_connection)
test_panelist.test_retrieve_scores_ordered_pair_by_id(30,
database_connection)
test_panelist.test_retrieve_scores_ordered_pair_by_slug("faith-salie",
database_connection)
# Testing retrieve panelist appearances
test_panelist.test_retrieve_yearly_appearances_by_id(14, database_connection)
test_panelist.test_retrieve_yearly_appearances_by_slug("luke-burbank",
database_connection)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def test_scorekeeper_module(database_connection: mysql.connector.connect):
"""Run tests against scorekeeper module"""
print("Testing wwdtm.scorekeeper module")
# Start Time
start_time = time.perf_counter()
# Testing scorekeeper.utility.id_exists
test_scorekeeper.test_id_exists(1, database_connection)
test_scorekeeper.test_id_not_exists(-1, database_connection)
# Testing scorekeeper.utility.slug_exists
test_scorekeeper.test_slug_exists("carl-kasell", database_connection)
test_scorekeeper.test_slug_not_exists("carl-kassel", database_connection)
# Testing retrieve all scorekeepers
test_scorekeeper.test_retrieve_all(database_connection)
test_scorekeeper.test_retrieve_all_ids(database_connection)
test_scorekeeper.test_retrieve_all_details(database_connection)
# Testing retrieve individual scorekeeper
test_scorekeeper.test_retrieve_by_id(11, database_connection)
test_scorekeeper.test_retrieve_by_slug("bill-kurtis", database_connection)
# Testing retrieve scorekeeper details
test_scorekeeper.test_retrieve_details_by_id(2, database_connection)
test_scorekeeper.test_retrieve_details_by_slug("korva-coleman",
database_connection)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def test_show_module(database_connection: mysql.connector.connect):
"""Run tests against show module"""
print("Testing wwdtm.show module")
# Start Time
start_time = time.perf_counter()
# Testing show.utility.id_exists
test_show.test_id_exists(1083, database_connection)
test_show.test_id_not_exists(-1083, database_connection)
# Testing show.utility.date_exists
test_show.test_date_exists(2006, 8, 19, database_connection)
test_show.test_date_not_exists(2006, 8, 20, database_connection)
# Testing retrieve basic show info
test_show.test_retrieve_by_id(47, database_connection)
test_show.test_retrieve_by_invalid_id(-47, database_connection)
test_show.test_retrieve_by_date(2018, 10, 27, database_connection)
test_show.test_retrieve_by_invalid_date(2018, 10, 28, database_connection)
test_show.test_retrieve_by_date_string("2007-03-24", database_connection)
test_show.test_retrieve_by_invalid_date_string("2007-03-",
database_connection)
# Testing retrieve multiple basic show info
test_show.test_retrieve_by_year(2006, database_connection)
test_show.test_retrieve_by_year_month(2006, 8, database_connection)
test_show.test_retrieve_all(database_connection)
test_show.test_retrieve_all_dates(database_connection)
test_show.test_retrieve_all_dates_tuple(database_connection)
test_show.test_retrieve_all_ids(database_connection)
test_show.test_retrieve_all_years_months(database_connection)
test_show.test_retrieve_all_years_months_tuple(database_connection)
# Testing retrieve recent basic show info
test_show.test_retrieve_recent(database_connection)
# Testing retrieve show months by year and show years
test_show.test_retrieve_months_by_year(2006, database_connection)
test_show.test_retrieve_years(database_connection)
# Testing retrieve show details
test_show.test_retrieve_details_by_id(1083, database_connection)
test_show.test_retrieve_details_by_invalid_id(-1083, database_connection)
test_show.test_retrieve_details_by_date(2018, 10, 27, database_connection)
test_show.test_retrieve_details_by_invalid_date(2018,
10,
2,
database_connection)
test_show.test_retrieve_details_by_date_string("2007-03-24",
database_connection)
test_show.test_retrieve_details_by_invalid_date_string("2007-03-02",
database_connection)
# Testing retrieve multiple show details
test_show.test_retrieve_details_by_year(2006, database_connection)
test_show.test_retrieve_details_by_year_month(2006, 12, database_connection)
test_show.test_retrieve_all_details(database_connection)
# Testing retrieve recent show details
test_show.test_retrieve_recent_details(database_connection)
# Testing retrieve show scores
test_show.test_retrieve_scores_by_year(2018, database_connection)
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
def load_config(app_environment):
"""Load configuration file from config.json"""
with open("config.json", "r") as config_file:
config_dict = json.load(config_file)
if app_environment.startswith("develop"):
if "development" in config_dict:
config = config_dict["development"]
else:
raise Exception("Missing 'development' section in config file")
elif app_environment.startswith("prod"):
if "production" in config_dict:
config = config_dict["production"]
else:
raise Exception("Missing 'production' section in config file")
else:
if "local" in config_dict:
config = config_dict["local"]
else:
raise Exception("Missing 'local' section in config file")
return config
def main():
"""Execute the test runs against the wwdtm modules"""
# Start Time
start_time = time.perf_counter()
app_environment = os.getenv("APP_ENV", "local").strip().lower()
print("Application Environment: {}".format(app_environment))
print()
config = load_config(app_environment)
database_connection = mysql.connector.connect(**config["database"])
test_guest_module(database_connection)
test_host_module(database_connection)
test_location_module(database_connection)
test_panelist_module(database_connection)
test_scorekeeper_module(database_connection)
test_show_module(database_connection)
database_connection.close()
# Calculate time elapsed
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print("Testing completed")
print("Total Time Elapsed: {}s\n".format(round(elapsed_time, 5)))
return
# Only run if executed as a script and not imported
if __name__ == "__main__":
main()