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