import time
import unittest
-from . import CmdException, exec_dashboard_cmd
+from . import CmdException
+from .helper import CLICommandTestMixin
from .. import mgr
from ..security import Scope, Permission
from ..services.access_control import load_access_control_db, \
SYSTEM_ROLES
-class AccessControlTest(unittest.TestCase):
- CONFIG_KEY_DICT = {}
-
- @classmethod
- def mock_set_module_option(cls, attr, val):
- cls.CONFIG_KEY_DICT[attr] = val
-
- @classmethod
- def mock_get_module_option(cls, attr, default=None):
- return cls.CONFIG_KEY_DICT.get(attr, default)
+class AccessControlTest(unittest.TestCase, CLICommandTestMixin):
@classmethod
def setUpClass(cls):
- mgr.set_module_option.side_effect = cls.mock_set_module_option
- mgr.get_module_option.side_effect = cls.mock_get_module_option
- # kludge below
- mgr.set_store.side_effect = cls.mock_set_module_option
- mgr.get_store.side_effect = cls.mock_get_module_option
+ cls.mock_kv_store()
mgr.ACCESS_CONTROL_DB = None
def setUp(self):
self.CONFIG_KEY_DICT.clear()
load_access_control_db()
- @classmethod
- def exec_cmd(cls, cmd, **kwargs):
- return exec_dashboard_cmd(None, cmd, **kwargs)
-
def load_persistent_db(self):
config_key = AccessControlDB.accessdb_config_key()
self.assertIn(config_key, self.CONFIG_KEY_DICT)
import cherrypy
import mock
-from .helper import ControllerTestCase
+from .helper import ControllerTestCase, KVStoreMockMixin
from ..controllers import RESTController, Controller
from ..tools import RequestLoggingTool
from .. import mgr
pass
-class ApiAuditingTest(ControllerTestCase):
- settings = {}
+class ApiAuditingTest(ControllerTestCase, KVStoreMockMixin):
def __init__(self, *args, **kwargs):
cherrypy.tools.request_logging = RequestLoggingTool()
cherrypy.config.update({'tools.request_logging.on': True})
super(ApiAuditingTest, self).__init__(*args, **kwargs)
- @classmethod
- def mock_set_module_option(cls, key, val):
- cls.settings[key] = val
-
- @classmethod
- def mock_get_module_option(cls, key, default=None):
- return cls.settings.get(key, default)
-
- @classmethod
- def setUpClass(cls):
- mgr.get_module_option.side_effect = cls.mock_get_module_option
- mgr.set_module_option.side_effect = cls.mock_set_module_option
-
@classmethod
def setup_server(cls):
cls.setup_controllers([FooResource])
def setUp(self):
+ self.mock_kv_store()
mgr.cluster_log = mock.Mock()
mgr.set_module_option('AUDIT_API_ENABLED', True)
mgr.set_module_option('AUDIT_API_LOG_PAYLOAD', True)
import unittest
from mock import Mock, patch
+from .helper import KVStoreMockMixin
from ..plugins.feature_toggles import FeatureToggles, Features
-class SettingsTest(unittest.TestCase):
- CONFIG = {
- 'url_prefix': '',
- }
-
+class SettingsTest(unittest.TestCase, KVStoreMockMixin):
@classmethod
def setUpClass(cls):
+ cls.mock_kv_store()
+ cls.CONFIG_KEY_DICT['url_prefix'] = ''
+
# Mock MODULE_OPTIONS
from .. import mgr
cls.mgr = mgr
- cls.mgr.get_module_option.side_effect = cls.CONFIG.__getitem__
- cls. mgr.set_module_option.side_effect = cls.CONFIG.__setitem__
# Populate real endpoint map
from ..controllers import load_controllers
# Initialize FeatureToggles plugin
cls.plugin = FeatureToggles()
- cls.CONFIG.update(
+ cls.CONFIG_KEY_DICT.update(
{k['name']: k['default'] for k in cls.plugin.get_options()})
cls.plugin.setup()
from mock import MagicMock, Mock
+from .helper import KVStoreMockMixin
from .. import mgr
from ..settings import Settings
from ..services import ganesha
from ..services.ganesha import GaneshaConf, Export, GaneshaConfParser
-class GaneshaConfTest(unittest.TestCase):
+class GaneshaConfTest(unittest.TestCase, KVStoreMockMixin):
export_1 = """
EXPORT {
Export_ID=1;
def _ioctx_list_objects_mock(self):
return [obj for _, obj in self.temp_store.items()]
- CONFIG_KEY_DICT = {}
-
- @classmethod
- def mock_set_module_option(cls, attr, val):
- cls.CONFIG_KEY_DICT[attr] = val
-
- @classmethod
- def mock_get_module_option(cls, attr, default):
- return cls.CONFIG_KEY_DICT.get(attr, default)
-
def setUp(self):
- mgr.set_module_option.side_effect = self.mock_set_module_option
- mgr.get_module_option.side_effect = self.mock_get_module_option
+ self.mock_kv_store()
Settings.GANESHA_CLUSTERS_RADOS_POOL_NAMESPACE = "ganesha/ns"
import errno
import unittest
-from .. import mgr
+from .helper import KVStoreMockMixin
from .. import settings
from ..controllers.settings import Settings as SettingsController
from ..settings import Settings, handle_option_command
from .helper import ControllerTestCase
-class SettingsTest(unittest.TestCase):
- CONFIG_KEY_DICT = {}
-
+class SettingsTest(unittest.TestCase, KVStoreMockMixin):
@classmethod
def setUpClass(cls):
# pylint: disable=protected-access
settings.Options.GRAFANA_ENABLED = (False, bool)
settings._OPTIONS_COMMAND_MAP = settings._options_command_map()
- @classmethod
- def mock_set_module_option(cls, attr, val):
- cls.CONFIG_KEY_DICT[attr] = val
-
- @classmethod
- def mock_get_module_option(cls, attr, default):
- return cls.CONFIG_KEY_DICT.get(attr, default)
-
def setUp(self):
- self.CONFIG_KEY_DICT.clear()
- mgr.set_module_option.side_effect = self.mock_set_module_option
- mgr.get_module_option.side_effect = self.mock_get_module_option
+ self.mock_kv_store()
if Settings.GRAFANA_API_HOST != 'localhost':
Settings.GRAFANA_API_HOST = 'localhost'
if Settings.GRAFANA_API_PORT != 3000:
"type object 'Options' has no attribute 'NON_EXISTENT_OPTION'")
-class SettingsControllerTest(ControllerTestCase):
- config_values = {}
-
+class SettingsControllerTest(ControllerTestCase, KVStoreMockMixin):
@classmethod
def setup_server(cls):
# pylint: disable=protected-access
SettingsController._cp_config['tools.authenticate.on'] = False
cls.setup_controllers([SettingsController])
- @classmethod
- def mock_set_module_option(cls, attr, val):
- cls.config_values[attr] = val
-
- @classmethod
- def mock_get_module_option(cls, attr, default):
- return cls.config_values.get(attr, default)
-
def setUp(self):
- self.config_values.clear()
- mgr.set_module_option.side_effect = self.mock_set_module_option
- mgr.get_module_option.side_effect = self.mock_get_module_option
+ self.mock_kv_store()
def test_settings_list(self):
self._get('/api/settings')
import unittest
from . import CmdException, exec_dashboard_cmd
-from .. import mgr
+from .helper import CLICommandTestMixin
from ..services.sso import handle_sso_command, load_sso_db
-class AccessControlTest(unittest.TestCase):
- CONFIG_KEY_DICT = {}
-
- @classmethod
- def mock_set_module_option(cls, attr, val):
- cls.CONFIG_KEY_DICT[attr] = val
-
- @classmethod
- def mock_get_module_option(cls, attr, default):
- return cls.CONFIG_KEY_DICT.get(attr, default)
-
+class AccessControlTest(unittest.TestCase, CLICommandTestMixin):
IDP_METADATA = '''<?xml version="1.0"?>
<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
</md:IDPSSODescriptor>
</md:EntityDescriptor>'''
- @classmethod
- def setUpClass(cls):
- mgr.set_module_option.side_effect = cls.mock_set_module_option
- mgr.get_module_option.side_effect = cls.mock_get_module_option
- # kludge below
- mgr.set_store.side_effect = cls.mock_set_module_option
- mgr.get_store.side_effect = cls.mock_get_module_option
-
def setUp(self):
- self.CONFIG_KEY_DICT.clear()
+ self.mock_kv_store()
load_sso_db()
@classmethod