]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/tests/test_feature_toggles.py
import quincy beta 17.1.0
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_feature_toggles.py
CommitLineData
11fdf7f2 1# -*- coding: utf-8 -*-
11fdf7f2
TL
2
3import unittest
f67539c2 4
9f95a23c
TL
5try:
6 from mock import Mock, patch
7except ImportError:
8 from unittest.mock import Mock, patch
11fdf7f2 9
f67539c2 10from ..plugins.feature_toggles import Actions, Features, FeatureToggles
a4b75251 11from ..tests import KVStoreMockMixin
11fdf7f2
TL
12
13
14class SettingsTest(unittest.TestCase, KVStoreMockMixin):
15 @classmethod
16 def setUpClass(cls):
17 cls.mock_kv_store()
18 cls.CONFIG_KEY_DICT['url_prefix'] = ''
19
20 # Mock MODULE_OPTIONS
21 from .. import mgr
22 cls.mgr = mgr
23
24 # Populate real endpoint map
a4b75251
TL
25 from ..controllers import BaseController
26 cls.controllers = BaseController.load_controllers()
11fdf7f2
TL
27
28 # Initialize FeatureToggles plugin
29 cls.plugin = FeatureToggles()
30 cls.CONFIG_KEY_DICT.update(
31 {k['name']: k['default'] for k in cls.plugin.get_options()})
32 cls.plugin.setup()
33
34 def test_filter_request_when_all_features_enabled(self):
35 """
36 This test iterates over all the registered endpoints to ensure that, with default
37 feature toggles, none is disabled.
38 """
39 import cherrypy
40
41 request = Mock()
42 for controller in self.controllers:
43 request.path_info = controller.get_path()
44 try:
45 self.plugin.filter_request_before_handler(request)
46 except cherrypy.HTTPError:
47 self.fail("Request filtered {} and it shouldn't".format(
48 request.path_info))
49
50 def test_filter_request_when_some_feature_enabled(self):
51 """
52 This test focuses on a single feature and checks whether it's actually
53 disabled
54 """
55 import cherrypy
56
57 self.plugin.register_commands()['handle_command'](
f67539c2 58 self.mgr, Actions.DISABLE, [Features.CEPHFS])
11fdf7f2
TL
59
60 with patch.object(self.plugin, '_get_feature_from_request',
61 return_value=Features.CEPHFS):
62 with self.assertRaises(cherrypy.HTTPError):
63 request = Mock()
64 self.plugin.filter_request_before_handler(request)