From: Ricardo Dias Date: Mon, 11 Mar 2019 15:44:51 +0000 (+0000) Subject: mgr/dashboard: tests: add mixin classes to mock mons KV store X-Git-Tag: v14.2.0~51^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a3708cc457753de66c7371cfbabd86065c3bbe02;p=ceph.git mgr/dashboard: tests: add mixin classes to mock mons KV store Signed-off-by: Ricardo Dias --- diff --git a/src/pybind/mgr/dashboard/tests/helper.py b/src/pybind/mgr/dashboard/tests/helper.py index 2efeba816bbf..fa3ff74e6532 100644 --- a/src/pybind/mgr/dashboard/tests/helper.py +++ b/src/pybind/mgr/dashboard/tests/helper.py @@ -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=''):