]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_rgw.py
4 import unittest
.mock
as mock
7 from ..controllers
.rgw
import Rgw
, RgwUser
8 from . import ControllerTestCase
# pylint: disable=no-name-in-module
11 class RgwControllerTestCase(ControllerTestCase
):
13 def setup_server(cls
):
14 Rgw
._cp
_config
['tools.authenticate.on'] = False # pylint: disable=protected-access
15 cls
.setup_controllers([Rgw
], '/test')
17 def test_status_no_service(self
):
18 mgr
.list_servers
.return_value
= []
19 self
._get
('/test/api/rgw/status')
20 self
.assertStatus(200)
21 self
.assertJsonBody({'available': False, 'message': 'No RGW service is running.'})
24 class RgwUserControllerTestCase(ControllerTestCase
):
26 def setup_server(cls
):
27 RgwUser
._cp
_config
['tools.authenticate.on'] = False # pylint: disable=protected-access
28 cls
.setup_controllers([RgwUser
], '/test')
30 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
31 def test_user_list(self
, mock_proxy
):
32 mock_proxy
.side_effect
= [{
34 'keys': ['test1', 'test2', 'test3'],
37 self
._get
('/test/api/rgw/user')
38 self
.assertStatus(200)
39 mock_proxy
.assert_has_calls([
40 mock
.call('GET', 'user?list', {})
42 self
.assertJsonBody(['test1', 'test2', 'test3'])
44 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
45 def test_user_list_marker(self
, mock_proxy
):
46 mock_proxy
.side_effect
= [{
48 'keys': ['test1', 'test2', 'test3'],
56 self
._get
('/test/api/rgw/user')
57 self
.assertStatus(200)
58 mock_proxy
.assert_has_calls([
59 mock
.call('GET', 'user?list', {}),
60 mock
.call('GET', 'user?list', {'marker': 'foo:bar'})
62 self
.assertJsonBody(['test1', 'test2', 'test3', 'admin'])
64 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
65 def test_user_list_duplicate_marker(self
, mock_proxy
):
66 mock_proxy
.side_effect
= [{
68 'keys': ['test1', 'test2', 'test3'],
73 'keys': ['test4', 'test5', 'test6'],
81 self
._get
('/test/api/rgw/user')
82 self
.assertStatus(500)
84 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
85 def test_user_list_invalid_marker(self
, mock_proxy
):
86 mock_proxy
.side_effect
= [{
88 'keys': ['test1', 'test2', 'test3'],
93 'keys': ['test4', 'test5', 'test6'],
101 self
._get
('/test/api/rgw/user')
102 self
.assertStatus(500)
104 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
105 @mock.patch
.object(RgwUser
, '_keys_allowed')
106 def test_user_get_with_keys(self
, keys_allowed
, mock_proxy
):
107 keys_allowed
.return_value
= True
108 mock_proxy
.return_value
= {
110 'user_id': 'my_user_id',
114 self
._get
('/test/api/rgw/user/testuser')
115 self
.assertStatus(200)
116 self
.assertInJsonBody('keys')
117 self
.assertInJsonBody('swift_keys')
119 @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy')
120 @mock.patch
.object(RgwUser
, '_keys_allowed')
121 def test_user_get_without_keys(self
, keys_allowed
, mock_proxy
):
122 keys_allowed
.return_value
= False
123 mock_proxy
.return_value
= {
125 'user_id': 'my_user_id',
129 self
._get
('/test/api/rgw/user/testuser')
130 self
.assertStatus(200)
131 self
.assertNotIn('keys', self
.json_body())
132 self
.assertNotIn('swift_keys', self
.json_body())