]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_feature_toggles.py
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / tests / test_feature_toggles.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import unittest
5 try:
6 from mock import Mock, patch
7 except ImportError:
8 from unittest.mock import Mock, patch
9
10 from . import KVStoreMockMixin
11 from ..plugins.feature_toggles import FeatureToggles, Features
12
13
14 class 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
25 from ..controllers import load_controllers
26 cls.controllers = load_controllers()
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'](
58 self.mgr, 'disable', ['cephfs'])
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)