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