]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/tests/test_feature_toggles.py
1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
7 from mock
import Mock
, patch
9 from unittest
.mock
import Mock
, patch
11 from ..plugins
.feature_toggles
import Actions
, Features
, FeatureToggles
12 from . import KVStoreMockMixin
# pylint: disable=no-name-in-module
15 class SettingsTest(unittest
.TestCase
, KVStoreMockMixin
):
19 cls
.CONFIG_KEY_DICT
['url_prefix'] = ''
25 # Populate real endpoint map
26 from ..controllers
import load_controllers
27 cls
.controllers
= load_controllers()
29 # Initialize FeatureToggles plugin
30 cls
.plugin
= FeatureToggles()
31 cls
.CONFIG_KEY_DICT
.update(
32 {k
['name']: k
['default'] for k
in cls
.plugin
.get_options()})
35 def test_filter_request_when_all_features_enabled(self
):
37 This test iterates over all the registered endpoints to ensure that, with default
38 feature toggles, none is disabled.
43 for controller
in self
.controllers
:
44 request
.path_info
= controller
.get_path()
46 self
.plugin
.filter_request_before_handler(request
)
47 except cherrypy
.HTTPError
:
48 self
.fail("Request filtered {} and it shouldn't".format(
51 def test_filter_request_when_some_feature_enabled(self
):
53 This test focuses on a single feature and checks whether it's actually
58 self
.plugin
.register_commands()['handle_command'](
59 self
.mgr
, Actions
.DISABLE
, [Features
.CEPHFS
])
61 with patch
.object(self
.plugin
, '_get_feature_from_request',
62 return_value
=Features
.CEPHFS
):
63 with self
.assertRaises(cherrypy
.HTTPError
):
65 self
.plugin
.filter_request_before_handler(request
)