1 from unittest import TestCase
2 from webtest import TestApp
3 from ceph_brag.tests import FunctionalTest
5 from pecan import request
7 class TestRootController(FunctionalTest):
8 def test_1_get_invalid_url_format(self):
9 response = self.app.get('/1/2/3', expect_errors=True)
10 assert response.status_int == 400
13 with open("sample.json", "rb") as myfile:
14 data = myfile.read().replace(b'\n', b'')
15 response = self.app.request('/', method='PUT', body=data)
16 assert response.status_int == 201
18 def test_3_put_invalid_json(self):
19 response = self.app.request('/', method='PUT', body=b'{asdfg', expect_errors=True)
20 assert response.status_int == 422
22 def test_4_put_invalid_entries_1(self):
23 response = self.app.request('/', method='PUT', body=b'{}', expect_errors=True)
24 assert response.status_int == 422
26 def test_5_put_incomplete_json(self):
27 response = self.app.request('/', method='PUT', body=b'{"uuid":"adfs-12312ad"}',
29 assert response.status_int == 422
32 response = self.app.get('/')
33 js = json.loads(response.body.decode('utf-8'))
38 response = self.app.get('/'+ci['uuid']+'/'+str(ci['num_versions']))
39 assert response.status_int == 200
41 def test_7_get_invalid_uuid(self):
42 response = self.app.get('/xxxxxx', expect_errors=True)
43 assert response.status_int == 400
45 def test_8_get_invalid_version(self):
46 response = self.app.get('/')
47 js = json.loads(response.body.decode('utf-8'))
52 response = self.app.get('/'+ci['uuid']+'/'+str(0), expect_errors=True)
53 assert response.status_int == 400
55 def test_9_delete_invalid_parameters(self):
56 response = self.app.delete('/', expect_errors=True)
57 assert response.status_int == 400
59 def test_91_delete_wrong_uuid(self):
60 response = self.app.delete('/?uuid=xxxx', expect_errors=True)
61 assert response.status_int == 400
63 def test_92_delete(self):
64 response = self.app.get('/')
65 js = json.loads(response.body.decode('utf-8'))
67 response = self.app.delete('/?uuid='+entry['uuid'])
68 assert response.status_int == 200