forked from nhs-nobleep/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.py
253 lines (211 loc) · 8.31 KB
/
app_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
import unittest
from flask import json
from app import *
class JobTestCase(unittest.TestCase):
def setUp(self):
db.create_all()
self.app = app.test_client()
def test_insert_response(self):
rv = self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
self.assertEqual(rv.mimetype, 'application/json')
def test_read_all_response(self):
rv = self.app.get('/job/read')
self.assertEqual(rv.mimetype, 'application/json')
def test_insert_and_read_all(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data['jobs'][0]['id'], 1)
self.assertEqual(data['jobs'][0]['patient_id'], 'patient_id')
def test_read_team_id_response(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
result = self.app.get('/job/read/1')
self.assertEqual(result.mimetype, 'application/json')
def test_read_team_id(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
result = self.app.get('/job/read/10')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data['jobs'][0]['team_id'], 10)
def test_update_response(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
up = self.app.post('/job/update/1', data={
'team_id': 20
}, follow_redirects=True)
self.assertEqual(up.mimetype, 'application/json')
self.assertEqual(json.loads(up.data.decode('utf-8'))['success'], True)
def test_update_team_id(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
up = self.app.post('/job/update/1', data={
'team_id': 20
}, follow_redirects=True)
self.assertEqual(json.loads(up.data.decode('utf-8'))['success'], True)
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data['jobs'][0]['id'], 1)
self.assertEqual(data['jobs'][0]['team_id'], 20)
def test_update_done(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
up = self.app.post('/job/update/1', data={
'done': 'Sun May 15 2016 12:17:36 GMT+0100 (BST)'
}, follow_redirects=True)
self.assertEqual(json.loads(up.data.decode('utf-8'))['success'], True)
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data, {'jobs': []})
def test_update_acknowledged(self):
self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
up = self.app.post('/job/update/1', data={
'acknowledged': 'Sun May 15 2016 12:17:36 GMT+0100 (BST)'
}, follow_redirects=True)
self.assertEqual(json.loads(up.data.decode('utf-8'))['success'], True)
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data['jobs'][0]['id'], 1)
self.assertEqual(type(data['jobs'][0]['acknowledged']), str)
def test_insert_urgency_4(self):
rv = self.app.post('/job/create', data={
'team_id': 10,
'patient_id': 'patient_id',
'urgency': 4,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
self.assertEqual(rv.mimetype, 'application/json')
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data, None)
def test_insert_team_id_missing(self):
rv = self.app.post('/job/create', data={
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
self.assertEqual(rv.mimetype, 'application/json')
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data, None)
def test_insert_team_id_empty(self):
rv = self.app.post('/job/create', data={
'team_id': '',
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
self.assertEqual(rv.mimetype, 'application/json')
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data, None)
def test_insert_team_id_none(self):
rv = self.app.post('/job/create', data={
'team_id': None,
'patient_id': 'patient_id',
'urgency': 3,
'creator_comment': 'creator_comment',
'doctor_comment': 'doctor_comment',
'bed': 'bed',
'ward': 'ward',
'location': 'location',
'creator_name': 'creator_name'
}, follow_redirects=True)
self.assertEqual(rv.mimetype, 'application/json')
result = self.app.get('/job/read')
data = json.loads(result.data.decode('utf-8'))
self.assertEqual(data, None)
def tearDown(self):
db.drop_all()
if __name__ == '__main__':
unittest.main()