forked from mxcube/mxcubeweb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unittest_mxcube3.py
58 lines (46 loc) · 1.81 KB
/
unittest_mxcube3.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
import unittest
import json
from mxcube3 import app as mxcube
from mxcube3 import hwr
mxcube.queue = hwr.getHardwareObject('/queue-model')
class TestCase(unittest.TestCase):
def setUp(self):
mxcube.config['TESTING'] = True
mxcube.config['WTF_CSRF_ENABLED'] = False
self.app = mxcube.test_client()
def tearDown(self):
pass
def test_1_add_item(self):
"""Test if we can add a sample."""
print '############### TEST ###############'
print 'TEST: add sample'
sample_to_add = {
'code': 'matr1_5',
'checked': True,
'sampleName': 'Sample-105',
'sampleID': '1:05',
'tasks': [],
'location': '1:5',
'defaultPrefix': 'local-user',
'type': 'Sample'
}
res = self.app.post('/mxcube/api/v0.1/queue',
data=json.dumps([sample_to_add]),
content_type='application/json'
)
self.assertTrue(res.status == '200 OK')
def test_2_get_item(self):
"""Test if we can retrieve the previously added sample."""
print '############### TEST ###############'
print 'TEST: get sample'
res = self.app.get('/mxcube/api/v0.1/queue')
self.assertTrue(res.status == '200 OK' and json.loads(res.data).get('1:05'))
def test_3_delete_sample(self):
"""Test if we can delte the previously added sample."""
print '############### TEST ###############'
print 'TEST: delete sample'
res = self.app.delete('/mxcube/api/v0.1/queue/1:05/undefined')
q = self.app.get('/mxcube/api/v0.1/queue')
self.assertTrue(res.status == '200 OK' and not json.loads(q.data).get('1:05'))
if __name__ == '__main__':
unittest.main()