Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / brag / server / ceph_brag / tests / test_functional.py
1 from unittest import TestCase
2 from webtest import TestApp
3 from ceph_brag.tests import FunctionalTest
4 import json, sys
5 from pecan import request
6
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
11
12     def test_2_put(self):
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
17
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
21
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
25
26     def test_5_put_incomplete_json(self):
27         response = self.app.request('/', method='PUT', body=b'{"uuid":"adfs-12312ad"}',
28                                     expect_errors=True)
29         assert response.status_int == 422
30
31     def test_6_get(self):
32         response = self.app.get('/')
33         js = json.loads(response.body.decode('utf-8'))
34         for entry in js:
35             ci = entry
36             break
37
38         response = self.app.get('/'+ci['uuid']+'/'+str(ci['num_versions']))
39         assert response.status_int == 200
40
41     def test_7_get_invalid_uuid(self):
42         response = self.app.get('/xxxxxx', expect_errors=True)
43         assert response.status_int == 400
44
45     def test_8_get_invalid_version(self):
46         response = self.app.get('/')
47         js = json.loads(response.body.decode('utf-8'))
48         for entry in js:
49             ci = entry
50             break
51
52         response = self.app.get('/'+ci['uuid']+'/'+str(0), expect_errors=True)
53         assert response.status_int == 400
54
55     def test_9_delete_invalid_parameters(self):
56         response = self.app.delete('/', expect_errors=True)
57         assert response.status_int == 400
58
59     def test_91_delete_wrong_uuid(self):
60         response = self.app.delete('/?uuid=xxxx', expect_errors=True)
61         assert response.status_int == 400
62
63     def test_92_delete(self):
64         response = self.app.get('/')
65         js = json.loads(response.body.decode('utf-8'))
66         for entry in js:
67             response = self.app.delete('/?uuid='+entry['uuid'])
68             assert response.status_int == 200