]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: tests: add mixin classes to mock mons KV store
authorRicardo Dias <rdias@suse.com>
Mon, 11 Mar 2019 15:44:51 +0000 (15:44 +0000)
committerRicardo Dias <rdias@suse.com>
Tue, 12 Mar 2019 10:15:57 +0000 (10:15 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard/tests/helper.py

index 2efeba816bbf10a945a54335f22794a0926038d0..fa3ff74e6532ca9a210aac3c8baf52b8cbb1cbe3 100644 (file)
@@ -10,12 +10,44 @@ import cherrypy
 from cherrypy._cptools import HandlerWrapperTool
 from cherrypy.test import helper
 
-from .. import logger
+from . import exec_dashboard_cmd
+from .. import logger, mgr
 from ..controllers import json_error_page, generate_controller_routes
 from ..services.auth import AuthManagerTool
 from ..services.exception import dashboard_exception_handler
 
 
+class KVStoreMockMixin(object):
+    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)
+
+    @classmethod
+    def mock_kv_store(cls):
+        cls.CONFIG_KEY_DICT.clear()
+        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
+
+    @classmethod
+    def get_key(cls, key):
+        return cls.CONFIG_KEY_DICT.get(key, None)
+
+
+class CLICommandTestMixin(KVStoreMockMixin):
+    @classmethod
+    def exec_cmd(cls, cmd, **kwargs):
+        return exec_dashboard_cmd(None, cmd, **kwargs)
+
+
 class ControllerTestCase(helper.CPWebCase):
     @classmethod
     def setup_controllers(cls, ctrl_classes, base_url=''):