-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_app.py
346 lines (290 loc) · 14.5 KB
/
test_app.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
import unittest
import requests
class test_test_app(unittest.TestCase):
def setUp(self):
print('setUp')
# clear databases
url = "https://lioneats.herokuapp.com/clear"
requests.get(url)
def tearDown(self):
print('tearDown')
# clear databases
url = "https://lioneats.herokuapp.com/clear"
requests.get(url)
''' Test login endpoint for happy case '''
def test_login_happy(self):
# first add an account
url = "https://lioneats.herokuapp.com/signup"
data = {"username": "hda0101", 'password': "testpwd"}
response = requests.post(url=url, json=data)
assert response.status_code == 200
# log in
url = "https://lioneats.herokuapp.com/login"
data = {"username": "hda0101", 'password': "testpwd"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(200)
assert response_body['status'] == "success"
''' Test login endpoint for wrong password given'''
def test_login_invalid_wrong_pwd(self):
# first add an account
url = "https://lioneats.herokuapp.com/signup"
data = {"username": "abc1234", 'password': "testpwd"}
response = requests.post(url=url, json=data)
assert response.status_code == 200
# now try logging in with incorrect password
url = "https://lioneats.herokuapp.com/login"
data = {"username": "abc1234", 'password': "idek"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(500)
assert response_body['reason'] == "wrong password"
''' Test login endpoint for an account that does not exist '''
def test_login_invalid_account_not_exist(self):
url = "https://lioneats.herokuapp.com/login"
data = {"username": "xyz1234", 'password': "testpwd"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(500)
assert response_body['reason'] == "account not exist"
''' Test signup endpoint for happy case '''
def test_signup_happy(self):
url = "https://lioneats.herokuapp.com/signup"
data = {"username": "abc1234", 'password': "pwdtest"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(200)
assert response_body['status'] == "success"
''' Test signup endpoint for account that already exists '''
def test_signup_invalid_account_exists(self):
# add account
url = "https://lioneats.herokuapp.com/signup"
data = {"username": "jdi8367", 'password': "greenapples"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response.status_code == 200
# attempt signup with previous account
url = "https://lioneats.herokuapp.com/signup"
data = {"username": "jdi8367", 'password': "greenapples"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(500)
assert response_body['reason'] == "account exists"
''' Test addreview endpoint for happy case'''
def test_addreview_happy(self):
# valid add review request
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': "Fumo", 'stars': 5, 'review': "Good",
'user': "dl3410"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response.status_code == 200
assert response_body['status'] == "success"
''' Test addreview endpoint for case when user tries
to add a review for a restaurant they've already reviewed'''
def test_addreview_invalid(self):
# valid add review request
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': "Fumo", 'stars': 5, 'review': "Good",
'user': "dl3410"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response.status_code == 200
# try adding a duplicate review
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': "Fumo", 'stars': 5, 'review': "Good",
'user': "dl3410"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status'] == "failure"
assert response_body['status_code'] == str(500)
# checks edit review endpoint given the user logged in
def test_edit_review_logged_in(self):
url = "https://lioneats.herokuapp.com/editreview"
data = {"uni": "yy3131"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(200)
assert response_body["status"] == "success"
# checks edit review search endpoint given a valid restaurant
def test_edit_review_search_valid(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
self.assertEqual(200, response.status_code)
url = "https://lioneats.herokuapp.com/edit_review_search"
data = {"uni": "yy3131", "res": "fumo"}
response = requests.post(url=url, json=data)
response_body = response.json()
assert response_body['status_code'] == str(200)
assert response_body["status"] == "success"
# checks edit review search endpoint given an invalid restaurant
def test_edit_review_search_invalid(self):
url = "https://lioneats.herokuapp.com/edit_review_search"
data = {"uni": "yy3131", "res": "random"}
response = requests.post(url=url, json=data)
self.assertEqual(response.json()["status"], "failure")
assert response.json()['status_code'] == str(500)
# checks update star and review endpoint given both required inputs
def test_update_star_and_review(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
self.assertEqual(200, response.status_code)
assert response.json()['status_code'] == str(200)
url = "https://lioneats.herokuapp.com/update_star_and_review"
data = {"star": 4, "review": "my go to place", "uni": "yy3131",
"res": "fumo"}
response = requests.post(url=url, json=data)
self.assertEqual(response.status_code, 200)
assert response.json()['status_code'] == str(200)
# Checks rest_display endpoint for all restaurants
def test_rest_display_all_happy(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_display"
data = {"star": 1}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=['fumo'], Average_Rating=[4])
assert response_body["res"] == exp_review
# Checks rest_display endpoint for restaurants above a certain rating
def test_rest_display_filter_happy(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
data = {'restaurant': 'koronet', 'stars': 1, 'review': 'bad food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_display"
data = {"star": 4}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=['fumo'], Average_Rating=[4])
assert response_body["res"] == exp_review
# Checks rest_display endpoint when there are no restaurants
def test_rest_display_none_happy(self):
url = "https://lioneats.herokuapp.com/rest_display"
data = {"star": 1}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=[], Average_Rating=[])
assert response_body["res"] == exp_review
# Checks rest_display endpoint for an invalid star rating
def test_rest_display_filter_invalid(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_display"
data = {"star": 6}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=[], Average_Rating=[])
assert response_body["res"] == exp_review
# Checks rest_info endpoint for all reviews
def test_rest_info_happy(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
data = {'restaurant': 'fumo', 'stars': 1, 'review': 'bad food',
'user': 'sa3892'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_info"
data = {'name': 'fumo', 'star': 1}
response = requests.get(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=['fumo', 'fumo'], Review=['bad food',
'good food'], Star_Rating=[1, 4], UNI=['sa3892',
'yy3131'])
assert response_body["res"] == exp_review
# Checks rest_info endpoint for reviews above a certain rating
def test_rest_info_filter_happy(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
data = {'restaurant': 'fumo', 'stars': 1, 'review': 'bad food',
'user': 'sa3892'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_info"
data = {'name': 'fumo', 'star': 4}
response = requests.get(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=['fumo'], Review=['good food'],
Star_Rating=[4], UNI=['yy3131'])
assert response_body["res"] == exp_review
url = "https://lioneats.herokuapp.com/rest_info"
data = {'name': 'fumo', 'star': 5}
response = requests.get(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=[], Review=[], Star_Rating=[], UNI=[])
assert response_body["res"] == exp_review
# Checks rest_info endpoint for restaurant that doesn't exist
def test_rest_info_invalid(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_info"
data = {'name': 'koronet', 'star': 1}
response = requests.get(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=[], Review=[], Star_Rating=[], UNI=[])
assert response_body["res"] == exp_review
# Checks rest_info endpoint for star rating that doesn't exist
def test_rest_info_filter_invalid(self):
url = "https://lioneats.herokuapp.com/addreview"
data = {'restaurant': 'fumo', 'stars': 4, 'review': 'good food',
'user': 'yy3131'}
response = requests.post(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
url = "https://lioneats.herokuapp.com/rest_info"
data = {'name': 'fumo', 'star': 6}
response = requests.get(url=url, json=data)
assert response.json()['status_code'] == str(200)
assert response.json()['status'] == "success"
response_body = response.json()
exp_review = dict(Name=[], Review=[], Star_Rating=[], UNI=[])
assert response_body["res"] == exp_review