From a3708cc457753de66c7371cfbabd86065c3bbe02 Mon Sep 17 00:00:00 2001 From: Ricardo Dias Date: Mon, 11 Mar 2019 15:44:51 +0000 Subject: [PATCH] mgr/dashboard: tests: add mixin classes to mock mons KV store Signed-off-by: Ricardo Dias --- src/pybind/mgr/dashboard/tests/helper.py | 34 +++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/tests/helper.py b/src/pybind/mgr/dashboard/tests/helper.py index 2efeba816bbf1..fa3ff74e6532c 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=''): -- 2.39.5