-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_base.py
339 lines (285 loc) · 15 KB
/
test_base.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
from mad_responder import app
import unittest
ANNOTATION_ID = 352848
ANNOTATIONPROP_ID = 20713727
ASSIGNMENT_ID = 155
ASSIGNMENTPROP_ID = 70397
MEDIA_ID = 109
MEDIAPROP_ID = 134443
OPENED = 0
STARTED = 0
class TestDiagnostics(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
# ******************************************************************************
# * Doc/diagnostic endpoints *
# ******************************************************************************
def test_blank(self):
response = self.app.get('/')
self.assertEqual(response.status_code, 200)
def test_spec(self):
response = self.app.get('/spec')
self.assertEqual(response.status_code, 200)
def test_doc(self):
response = self.app.get('/doc')
self.assertEqual(response.status_code, 200)
def test_stats(self):
response = self.app.get('/stats')
self.assertEqual(response.status_code, 200)
self.assertGreater(response.json['stats']['requests'], 0)
def test_processlist_columns(self):
response = self.app.get('/processlist/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 8)
def test_ping(self):
response = self.app.get('/ping')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['rest']['error'], False)
class TestProcesses(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
def test_processlist(self):
response = self.app.get('/processlist')
self.assertEqual(response.status_code, 200)
self.assertGreater(len(response.json['data']), 1)
class TestErrors(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
# ******************************************************************************
# * Forced error endpoints *
# ******************************************************************************
def test_sqlerror(self):
response = self.app.get('/test_sqlerror')
self.assertEqual(response.status_code, 500)
self.assertIn("MySQL error", response.json['rest']['error'])
def test_other_error(self):
response = self.app.get('/test_other_error')
self.assertEqual(response.status_code, 500)
self.assertIn(response.json['rest']['error'], ["Error: division by zero", "MySQL error [1146]: Table 'mad.cv_term_vw' doesn't exist"])
class TestContent(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
# ******************************************************************************
# * CV endpoints *
# ******************************************************************************
def test_cv_ids(self):
response = self.app.get('/cv_ids?name=body_type')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0], 70)
response = self.app.get('/cv_ids?name=aint_no_such_cv')
self.assertEqual(response.status_code, 404)
def test_cvs(self):
response = self.app.get('/cvs?id=70')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['name'], 'body_type')
response = self.app.get('/cvs?id=70&_columns=display_name')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['display_name'], 'Body Type')
response = self.app.get('/cvs?_columns=name&_sort=name')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['name'], 'assignment_types')
response = self.app.get('/cvs?id=0')
self.assertEqual(response.status_code, 404)
def test_cvs_columns(self):
response = self.app.get('/cvs/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 7)
def test_cvs_id(self):
response = self.app.get('/cvs/70')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['name'], 'body_type')
response = self.app.get('/cvs/0')
self.assertEqual(response.status_code, 404)
def test_cvterm_ids(self):
response = self.app.get('/cvterm_ids?cv_term=substack')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0], 1824)
response = self.app.get('/cvterm_ids?cv_term=aint_no_such_cvterm')
self.assertEqual(response.status_code, 404)
def test_cverms(self):
response = self.app.get('/cvterms?id=1824')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['cv_term'], 'substack')
response = self.app.get('/cvterms?id=0')
self.assertEqual(response.status_code, 404)
def test_cvterms_columns(self):
response = self.app.get('/cvterms/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 9)
def test_cvterms_id(self):
response = self.app.get('/cvterms/1824')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['cv_term'], 'substack')
response = self.app.get('/cvterms/0')
self.assertEqual(response.status_code, 404)
# ******************************************************************************
# * Annotation endpoints *
# ******************************************************************************
def test_annotation_ids(self):
response = self.app.get('/annotation_ids?media=00084_2328-2952_6339-6963_3385-4009')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 2)
response = self.app.get('/annotation_ids?media=no_such_media')
self.assertEqual(response.status_code, 404)
def test_annotations(self):
response = self.app.get('/annotations?media=00084_2328-2952_6339-6963_3385-4009')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 2)
response = self.app.get('/annotations?media=no_such_media')
self.assertEqual(response.status_code, 404)
def test_annotation_columns(self):
response = self.app.get('/annotations/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 11)
def test_annotation_id(self):
response = self.app.get('/annotations/' + str(ANNOTATION_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['media'], 'hb_focused')
response = self.app.get('/annotations/0')
self.assertEqual(response.status_code, 404)
def test_annotationprop_ids(self):
response = self.app.get('/annotationprop_ids?type=manager_assignment_note')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 3)
response = self.app.get('/annotationprop_ids?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_annotationprops(self):
response = self.app.get('/annotationprops?type=manager_assignment_note')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 3)
response = self.app.get('/annotationprops?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_annotationprop_columns(self):
response = self.app.get('/annotationprops/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 8)
def test_annotationprop_id(self):
response = self.app.get('/annotationprops/' + str(ANNOTATIONPROP_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['type'], 'blocks_annotated')
response = self.app.get('/annotationprops/0')
self.assertEqual(response.status_code, 404)
# ******************************************************************************
# * Assignment endpoints *
# ******************************************************************************
def test_assignment_ids(self):
response = self.app.get('/assignment_ids?user=shinomiyaa')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 2955)
response = self.app.get('/assignment_ids?user=no_such_user')
self.assertEqual(response.status_code, 404)
def test_assignments(self):
response = self.app.get('/assignments?user=shinomiyaa')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 2955)
response = self.app.get('/assignments?user=no_such_user')
self.assertEqual(response.status_code, 404)
def test_assignment_columns(self):
response = self.app.get('/assignments/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 11)
def test_assignment_id(self):
response = self.app.get('/assignments/' + str(ASSIGNMENT_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['is_complete'], 1)
response = self.app.get('/assignments/0')
self.assertEqual(response.status_code, 404)
def test_assignments_completed(self):
response = self.app.get('/assignments_completed?annotation=psd_annot')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 1044)
def test_assignments_open(self):
response = self.app.get('/assignments_open')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 1)
OPENED = len(response.json['data'])
def test_assignments_started(self):
response = self.app.get('/assignments_started')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 1)
STARTED = len(response.json['data'])
def test_assignments_remaining(self):
response = self.app.get('/assignments_remaining')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), OPENED + STARTED)
def test_assignmentprop_ids(self):
response = self.app.get('/assignmentprop_ids?type=tbars_missing_psds')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 25)
response = self.app.get('/assignmentprop_ids?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_assignmentprops(self):
response = self.app.get('/assignmentprops?type=tbars_missing_psds')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 25)
response = self.app.get('/assignmentprops?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_assignmentprop_columns(self):
response = self.app.get('/assignmentprops/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 7)
def test_assignmentprop_id(self):
response = self.app.get('/assignmentprops/' + str(ASSIGNMENTPROP_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['type'], 'assign_dvid_url')
response = self.app.get('/assignmentprops/0')
self.assertEqual(response.status_code, 404)
# ******************************************************************************
# * DVID endpoints *
# ******************************************************************************
def test_dvid_instances(self):
response = self.app.get('/dvid_instances?media=cx')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['url'], 'http://emdata2.int.janelia.org:8000')
response = self.app.get('/dvid_instances?media=no_such_media')
self.assertEqual(response.status_code, 404)
# ******************************************************************************
# * Media endpoints *
# ******************************************************************************
def test_media_ids(self):
response = self.app.get('/media_ids?type=stack')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 9)
response = self.app.get('/media_ids?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_media(self):
response = self.app.get('/media?type=stack')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 9)
response = self.app.get('/media?type=no_such_type')
self.assertEqual(response.status_code, 404)
def test_media_columns(self):
response = self.app.get('/media/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 6)
def test_media_id(self):
response = self.app.get('/media/' + str(MEDIA_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['type'], 'stack')
response = self.app.get('/media/0')
self.assertEqual(response.status_code, 404)
def test_mediaprop_ids(self):
response = self.app.get('/mediaprop_ids?media=hb_recleave')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 9)
response = self.app.get('/mediaprop_ids?media=no_such_media')
self.assertEqual(response.status_code, 404)
def test_mediaprops(self):
response = self.app.get('/mediaprops?media=hb_recleave')
self.assertEqual(response.status_code, 200)
self.assertGreaterEqual(len(response.json['data']), 9)
response = self.app.get('/mediaprops?media=no_such_media')
self.assertEqual(response.status_code, 404)
def test_mediaprop_columns(self):
response = self.app.get('/mediaprops/columns')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json['columns']), 6)
def test_mediaprop_id(self):
response = self.app.get('/mediaprops/' + str(MEDIAPROP_ID))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json['data'][0]['media'], 'hb_recleave')
response = self.app.get('/mediaprops/0')
self.assertEqual(response.status_code, 404)
# ******************************************************************************
if __name__ == '__main__':
unittest.main()