]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_rgw.py
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_rgw.py
1 import mock
2
3 from . import ControllerTestCase
4 from ..controllers.rgw import RgwUser
5
6
7 class RgwUserControllerTestCase(ControllerTestCase):
8 @classmethod
9 def setup_server(cls):
10 RgwUser._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access
11 cls.setup_controllers([RgwUser], '/test')
12
13 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
14 def test_user_list(self, mock_proxy):
15 mock_proxy.side_effect = [{
16 'count': 3,
17 'keys': ['test1', 'test2', 'test3'],
18 'truncated': False
19 }]
20 self._get('/test/api/rgw/user')
21 self.assertStatus(200)
22 mock_proxy.assert_has_calls([
23 mock.call('GET', 'user?list', {})
24 ])
25 self.assertJsonBody(['test1', 'test2', 'test3'])
26
27 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
28 def test_user_list_marker(self, mock_proxy):
29 mock_proxy.side_effect = [{
30 'count': 3,
31 'keys': ['test1', 'test2', 'test3'],
32 'marker': 'foo:bar',
33 'truncated': True
34 }, {
35 'count': 1,
36 'keys': ['admin'],
37 'truncated': False
38 }]
39 self._get('/test/api/rgw/user')
40 self.assertStatus(200)
41 mock_proxy.assert_has_calls([
42 mock.call('GET', 'user?list', {}),
43 mock.call('GET', 'user?list', {'marker': 'foo:bar'})
44 ])
45 self.assertJsonBody(['test1', 'test2', 'test3', 'admin'])
46
47 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
48 def test_user_list_duplicate_marker(self, mock_proxy):
49 mock_proxy.side_effect = [{
50 'count': 3,
51 'keys': ['test1', 'test2', 'test3'],
52 'marker': 'foo:bar',
53 'truncated': True
54 }, {
55 'count': 3,
56 'keys': ['test4', 'test5', 'test6'],
57 'marker': 'foo:bar',
58 'truncated': True
59 }, {
60 'count': 1,
61 'keys': ['admin'],
62 'truncated': False
63 }]
64 self._get('/test/api/rgw/user')
65 self.assertStatus(500)
66
67 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
68 def test_user_list_invalid_marker(self, mock_proxy):
69 mock_proxy.side_effect = [{
70 'count': 3,
71 'keys': ['test1', 'test2', 'test3'],
72 'marker': 'foo:bar',
73 'truncated': True
74 }, {
75 'count': 3,
76 'keys': ['test4', 'test5', 'test6'],
77 'marker': '',
78 'truncated': True
79 }, {
80 'count': 1,
81 'keys': ['admin'],
82 'truncated': False
83 }]
84 self._get('/test/api/rgw/user')
85 self.assertStatus(500)