-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
192 lines (168 loc) · 9.27 KB
/
Copy pathtest_api.py
File metadata and controls
192 lines (168 loc) · 9.27 KB
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
from flask import Flask,jsonify
from flask_testing import TestCase
from app import create_app, db
class ApiTests(TestCase):
def create_app(self):
return create_app()
def test_get_all_lists(self):
response = self.client.get('/lists')
self.assert200(response)
self.assertTrue('lists' in response.json)
def test_get_list(self):
response = self.client.get('/lists/ce3583a6-17ea-472f-9cec-cc575eb3c687')
self.assert200(response)
self.assertEqual(response.json['title'],'Demo Title')
def test_get_list_404(self):
response = self.client.get('/lists/bad-id')
self.assert404(response)
self.assertEqual(response.json['message'],'Could not locate list with id: bad-id')
def test_create_list(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
self.assertEqual(response.json['title'],'Test Title')
self.assertEqual(response.json['description'],'Test Description')
def test_create_list_400(self):
response=self.client.post('/lists',
data='{"description": "Test Description"}',
content_type='application/json')
self.assert400(response)
def test_update_list(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
id = response.json['id']
updateResponse=self.client.put('/lists/{}'.format(id),
data='{"description": "Updated Test Description","title": "Updated Test Title"}',
content_type='application/json')
self.assert200(updateResponse)
self.assertEqual(updateResponse.json['title'],'Updated Test Title')
self.assertEqual(updateResponse.json['description'],'Updated Test Description')
def test_update_list_400(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
id = response.json['id']
updateResponse=self.client.put('/lists/{}'.format(id),
data='{"description": "Updated Test Description"}',
content_type='application/json')
self.assert400(updateResponse)
def test_update_list_404(self):
updateResponse=self.client.put('/lists/bad-id',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assert404(updateResponse)
self.assertEqual(updateResponse.json['message'],'Could not locate list with id: bad-id')
def test_delete_list(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
id = response.json['id']
deleteResponse=self.client.delete('/lists/{}'.format(id))
self.assertEqual(deleteResponse.status_code, 204)
def test_delete_list_404(self):
deleteResponse=self.client.delete('/lists/bad-id')
self.assert404(deleteResponse)
def test_get_all_items(self):
response = self.client.get('/lists/ce3583a6-17ea-472f-9cec-cc575eb3c687/items')
self.assert200(response)
self.assertTrue('items' in response.json)
def test_get_item(self):
response = self.client.get('/lists/ce3583a6-17ea-472f-9cec-cc575eb3c687/items/1b575cdb-a06c-44cf-8931-6dee69926ab5')
self.assert200(response)
self.assertEqual(response.json['description'],'Item One')
def test_get_item_404(self):
response = self.client.get('/lists/ce3583a6-17ea-472f-9cec-cc575eb3c687/items/bad-id')
self.assert404(response)
def test_create_item(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
id = response.json['id']
itemResponse = self.client.post('/lists/{}/items'.format(id),
data='{"description": "Test Description","status": "incomplete"}',
content_type='application/json')
self.assertEqual(itemResponse.status_code, 201)
self.assertTrue('id' in itemResponse.json)
self.assertEqual(itemResponse.json['description'],'Test Description')
self.assertEqual(itemResponse.json['status'],'incomplete')
def test_create_item_400(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
id = response.json['id']
itemResponse = self.client.post('/lists/{}/items'.format(id),
data='{"status": "incomplete"}',
content_type='application/json')
self.assert400(itemResponse)
def test_update_item(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
list_id = response.json['id']
itemResponse = self.client.post('/lists/{}/items'.format(list_id),
data='{"description": "Test Description","status": "incomplete"}',
content_type='application/json')
self.assertEqual(itemResponse.status_code, 201)
self.assertTrue('id' in itemResponse.json)
item_id = itemResponse.json['id']
updateReponse = self.client.put('/lists/{}/items/{}'.format(list_id,item_id),
data='{"description": "Updated Test Description","status": "complete"}',
content_type='application/json')
self.assert200(updateReponse)
self.assertEqual(updateReponse.json['description'],'Updated Test Description')
self.assertEqual(updateReponse.json['status'],'complete')
def test_update_item_400(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
list_id = response.json['id']
itemResponse = self.client.post('/lists/{}/items'.format(list_id),
data='{"description": "Test Description","status": "incomplete"}',
content_type='application/json')
self.assertEqual(itemResponse.status_code, 201)
self.assertTrue('id' in itemResponse.json)
item_id = itemResponse.json['id']
updateReponse = self.client.put('/lists/{}/items/{}'.format(list_id,item_id),
data='{"description": "Updated Test Description","status": "bad_status"}',
content_type='application/json')
self.assert400(updateReponse)
def test_update_item_404(self):
updateReponse = self.client.put('/lists/bad-id/items/bad-id',
data='{"description": "Updated Test Description","status": "complete"}',
content_type='application/json')
self.assert404(updateReponse)
def test_delete_item(self):
response=self.client.post('/lists',
data='{"description": "Test Description","title": "Test Title"}',
content_type='application/json')
self.assertEqual(response.status_code, 201)
self.assertTrue('id' in response.json)
list_id = response.json['id']
itemResponse = self.client.post('/lists/{}/items'.format(list_id),
data='{"description": "Test Description","status": "incomplete"}',
content_type='application/json')
self.assertEqual(itemResponse.status_code, 201)
self.assertTrue('id' in itemResponse.json)
item_id = itemResponse.json['id']
deleteResponse=self.client.delete('/lists/{}/items/{}'.format(list_id, item_id))
self.assertEqual(deleteResponse.status_code, 204)
def test_delete_item_404(self):
deleteResponse=self.client.delete('/lists/bad-id/items/bad-id')
self.assert404(deleteResponse)