From a6aeded5141ec3a959a86aa4002ccf5ac8d0a523 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alfonso=20Mart=C3=ADnez?= Date: Wed, 3 Nov 2021 10:17:21 +0100 Subject: [PATCH] mgr/dashboard: python unit tests refactoring MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Controller tests: cherrypy config: authentication disabled by default; ability to pass custom config (e.g. enable authentication). * Auth controller: add tests; test that unauthorized request fails when authentication is enabled. * DocsTest: clear ENDPOINT_MAP so the test_gen_tags test becomes deterministic. * pylint: disable=no-name-in-module: fix imports in tests. Fixes: https://tracker.ceph.com/issues/53083 Signed-off-by: Alfonso Martínez --- doc/dev/developer_guide/dash-devel.rst | 8 ++-- src/pybind/mgr/dashboard/tests/__init__.py | 9 +++- .../dashboard/tests/test_access_control.py | 2 +- .../mgr/dashboard/tests/test_api_auditing.py | 2 +- src/pybind/mgr/dashboard/tests/test_auth.py | 46 +++++++++++++++++++ src/pybind/mgr/dashboard/tests/test_cephfs.py | 2 +- .../mgr/dashboard/tests/test_controllers.py | 2 +- src/pybind/mgr/dashboard/tests/test_docs.py | 9 ++-- .../tests/test_erasure_code_profile.py | 4 +- .../mgr/dashboard/tests/test_exceptions.py | 2 +- .../dashboard/tests/test_feature_toggles.py | 2 +- .../mgr/dashboard/tests/test_grafana.py | 4 +- src/pybind/mgr/dashboard/tests/test_home.py | 2 +- src/pybind/mgr/dashboard/tests/test_host.py | 6 +-- src/pybind/mgr/dashboard/tests/test_iscsi.py | 10 +--- .../mgr/dashboard/tests/test_orchestrator.py | 4 +- src/pybind/mgr/dashboard/tests/test_osd.py | 3 +- .../mgr/dashboard/tests/test_plugin_debug.py | 2 +- src/pybind/mgr/dashboard/tests/test_pool.py | 4 +- .../mgr/dashboard/tests/test_prometheus.py | 4 +- .../mgr/dashboard/tests/test_rbd_mirroring.py | 15 +----- .../mgr/dashboard/tests/test_rest_tasks.py | 4 +- src/pybind/mgr/dashboard/tests/test_rgw.py | 5 +- .../mgr/dashboard/tests/test_rgw_client.py | 2 +- .../mgr/dashboard/tests/test_settings.py | 5 +- src/pybind/mgr/dashboard/tests/test_sso.py | 2 +- src/pybind/mgr/dashboard/tests/test_tools.py | 2 +- .../mgr/dashboard/tests/test_versioning.py | 2 +- 28 files changed, 87 insertions(+), 77 deletions(-) diff --git a/doc/dev/developer_guide/dash-devel.rst b/doc/dev/developer_guide/dash-devel.rst index a5ffaa32c17..de6f90c3474 100644 --- a/doc/dev/developer_guide/dash-devel.rst +++ b/doc/dev/developer_guide/dash-devel.rst @@ -1736,8 +1736,8 @@ If we want to write a unit test for the above ``Ping`` controller, create a class PingTest(ControllerTestCase): @classmethod def setup_test(cls): - Ping._cp_config['tools.authenticate.on'] = False - cls.setup_controllers([Ping]) + cp_config = {'tools.authenticate.on': True} + cls.setup_controllers([Ping], cp_config=cp_config) def test_ping(self): self._get("/api/ping") @@ -1747,8 +1747,8 @@ If we want to write a unit test for the above ``Ping`` controller, create a The ``ControllerTestCase`` class starts by initializing a CherryPy webserver. Then it will call the ``setup_test()`` class method where we can explicitly load the controllers that we want to test. In the above example we are only -loading the ``Ping`` controller. We can also disable authentication of a -controller at this stage, as depicted in the example. +loading the ``Ping`` controller. We can also provide ``cp_config`` in order to +update the controller's cherrypy config (e.g. enable authentication as shown in the example). How to update or create new dashboards in grafana? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/pybind/mgr/dashboard/tests/__init__.py b/src/pybind/mgr/dashboard/tests/__init__.py index 9e73b85d608..6ae01cca172 100644 --- a/src/pybind/mgr/dashboard/tests/__init__.py +++ b/src/pybind/mgr/dashboard/tests/__init__.py @@ -5,6 +5,7 @@ import json import logging import threading import time +from typing import Any, Dict from unittest.mock import Mock import cherrypy @@ -101,12 +102,18 @@ class ControllerTestCase(helper.CPWebCase): _endpoints_cache = {} @classmethod - def setup_controllers(cls, ctrl_classes, base_url=''): + def setup_controllers(cls, ctrl_classes, base_url='', cp_config: Dict[str, Any] = None): if not isinstance(ctrl_classes, list): ctrl_classes = [ctrl_classes] mapper = cherrypy.dispatch.RoutesDispatcher() endpoint_list = [] for ctrl in ctrl_classes: + ctrl._cp_config = { + 'tools.dashboard_exception_handler.on': True, + 'tools.authenticate.on': False + } + if cp_config: + ctrl._cp_config.update(cp_config) inst = ctrl() # We need to cache the controller endpoints because diff --git a/src/pybind/mgr/dashboard/tests/test_access_control.py b/src/pybind/mgr/dashboard/tests/test_access_control.py index 3a435eb9739..b97082cbd47 100644 --- a/src/pybind/mgr/dashboard/tests/test_access_control.py +++ b/src/pybind/mgr/dashboard/tests/test_access_control.py @@ -15,7 +15,7 @@ from ..security import Permission, Scope from ..services.access_control import SYSTEM_ROLES, AccessControlDB, \ PasswordPolicy, load_access_control_db, password_hash from ..settings import Settings -from . import CLICommandTestMixin, CmdException # pylint: disable=no-name-in-module +from ..tests import CLICommandTestMixin, CmdException class AccessControlTest(unittest.TestCase, CLICommandTestMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_api_auditing.py b/src/pybind/mgr/dashboard/tests/test_api_auditing.py index de6e7cdc5f7..dd47b26c4e8 100644 --- a/src/pybind/mgr/dashboard/tests/test_api_auditing.py +++ b/src/pybind/mgr/dashboard/tests/test_api_auditing.py @@ -10,7 +10,7 @@ except ImportError: from .. import mgr from ..controllers import RESTController, Router -from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase, KVStoreMockMixin # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tests/test_auth.py b/src/pybind/mgr/dashboard/tests/test_auth.py index 6f1d2a084ec..698db40e1e5 100644 --- a/src/pybind/mgr/dashboard/tests/test_auth.py +++ b/src/pybind/mgr/dashboard/tests/test_auth.py @@ -1,7 +1,15 @@ import unittest +from unittest.mock import Mock, patch from .. import mgr +from ..controllers.auth import Auth from ..services.auth import JwtManager +from ..tests import ControllerTestCase + +mgr.get_module_option.return_value = JwtManager.JWT_TOKEN_TTL +mgr.get_store.return_value = 'jwt_secret' +mgr.ACCESS_CTRL_DB = Mock() +mgr.ACCESS_CTRL_DB.get_attempt.return_value = 1 class JwtManagerTest(unittest.TestCase): @@ -18,3 +26,41 @@ class JwtManagerTest(unittest.TestCase): self.assertIsInstance(decoded_token, dict) self.assertEqual(decoded_token['iss'], 'ceph-dashboard') self.assertEqual(decoded_token['username'], 'my-username') + + +class AuthTest(ControllerTestCase): + + @classmethod + def setup_server(cls): + cls.setup_controllers([Auth]) + + def test_request_not_authorized(self): + self.setup_controllers([Auth], cp_config={'tools.authenticate.on': True}) + self._post('/api/auth/logout') + self.assertStatus(401) + + @patch('dashboard.controllers.auth.JwtManager.gen_token', Mock(return_value='my-token')) + @patch('dashboard.controllers.auth.AuthManager.authenticate', Mock(return_value={ + 'permissions': {'read-only': ['read']}, + 'pwdExpirationDate': 1000000, + 'pwdUpdateRequired': False + })) + def test_login(self): + self._post('/api/auth', {'username': 'my-user', 'password': 'my-pass'}) + self.assertStatus(201) + self.assertJsonBody({ + 'token': 'my-token', + 'username': 'my-user', + 'permissions': {'read-only': ['read']}, + 'pwdExpirationDate': 1000000, + 'sso': False, + 'pwdUpdateRequired': False + }) + + @patch('dashboard.controllers.auth.JwtManager', Mock()) + def test_logout(self): + self._post('/api/auth/logout') + self.assertStatus(200) + self.assertJsonBody({ + 'redirect_url': '#/login' + }) diff --git a/src/pybind/mgr/dashboard/tests/test_cephfs.py b/src/pybind/mgr/dashboard/tests/test_cephfs.py index 5c35cab329c..ae425354384 100644 --- a/src/pybind/mgr/dashboard/tests/test_cephfs.py +++ b/src/pybind/mgr/dashboard/tests/test_cephfs.py @@ -7,7 +7,7 @@ except ImportError: from unittest.mock import patch, Mock from ..controllers.cephfs import CephFS -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase class MetaDataMock(object): diff --git a/src/pybind/mgr/dashboard/tests/test_controllers.py b/src/pybind/mgr/dashboard/tests/test_controllers.py index 8daa2dd0ea5..0f1662ebd0a 100644 --- a/src/pybind/mgr/dashboard/tests/test_controllers.py +++ b/src/pybind/mgr/dashboard/tests/test_controllers.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from ..controllers import APIRouter, BaseController, Endpoint, RESTController, Router -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase @Router("/btest/{key}", base_url="/ui", secure=False) diff --git a/src/pybind/mgr/dashboard/tests/test_docs.py b/src/pybind/mgr/dashboard/tests/test_docs.py index 3610144b2cc..ded0c140e67 100644 --- a/src/pybind/mgr/dashboard/tests/test_docs.py +++ b/src/pybind/mgr/dashboard/tests/test_docs.py @@ -3,10 +3,10 @@ import unittest from ..api.doc import SchemaType -from ..controllers import APIDoc, APIRouter, Endpoint, EndpointDoc, RESTController +from ..controllers import ENDPOINT_MAP, APIDoc, APIRouter, Endpoint, EndpointDoc, RESTController from ..controllers._version import APIVersion from ..controllers.docs import Docs -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase # Dummy controller and endpoint that can be assigned with @EndpointDoc and @GroupDoc @@ -67,6 +67,7 @@ class DocDecoratorsTest(ControllerTestCase): class DocsTest(ControllerTestCase): @classmethod def setup_server(cls): + ENDPOINT_MAP.clear() cls.setup_controllers([DecoratedController, Docs], "/test") def test_type_to_str(self): @@ -121,8 +122,8 @@ class DocsTest(ControllerTestCase): self.assertTrue(any(base in key.split('/')[1] for base in ['api', 'ui-api'])) def test_gen_tags(self): - outcome = Docs()._gen_tags(False)[0] - self.assertEqual({'description': 'Group description', 'name': 'FooGroup'}, outcome) + outcome = Docs._gen_tags(False) + self.assertEqual([{'description': 'Group description', 'name': 'FooGroup'}], outcome) class TestEndpointDocWrapper(unittest.TestCase): diff --git a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py index 8ff1490708f..d1b032a514f 100644 --- a/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py +++ b/src/pybind/mgr/dashboard/tests/test_erasure_code_profile.py @@ -2,7 +2,7 @@ from .. import mgr from ..controllers.erasure_code_profile import ErasureCodeProfile -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase class ErasureCodeProfileTest(ControllerTestCase): @@ -21,8 +21,6 @@ class ErasureCodeProfileTest(ControllerTestCase): 'fs_map': {'filesystems': []}, }[key] - # pylint: disable=protected-access - ErasureCodeProfile._cp_config['tools.authenticate.on'] = False cls.setup_controllers([ErasureCodeProfile]) def test_list(self): diff --git a/src/pybind/mgr/dashboard/tests/test_exceptions.py b/src/pybind/mgr/dashboard/tests/test_exceptions.py index 8e20bfb2373..ff4edabddc5 100644 --- a/src/pybind/mgr/dashboard/tests/test_exceptions.py +++ b/src/pybind/mgr/dashboard/tests/test_exceptions.py @@ -8,8 +8,8 @@ from ..controllers import Endpoint, RESTController, Router, Task from ..services.ceph_service import SendCommandError from ..services.exception import handle_rados_error, \ handle_send_command_error, serialize_dashboard_exception +from ..tests import ControllerTestCase from ..tools import NotificationQueue, TaskManager, ViewCache -from . import ControllerTestCase # pylint: disable=no-name-in-module # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py index fce7c60720e..3ba434dee87 100644 --- a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py +++ b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py @@ -8,7 +8,7 @@ except ImportError: from unittest.mock import Mock, patch from ..plugins.feature_toggles import Actions, Features, FeatureToggles -from . import KVStoreMockMixin # pylint: disable=no-name-in-module +from ..tests import KVStoreMockMixin class SettingsTest(unittest.TestCase, KVStoreMockMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_grafana.py b/src/pybind/mgr/dashboard/tests/test_grafana.py index d9b15e8231e..f54219c9f13 100644 --- a/src/pybind/mgr/dashboard/tests/test_grafana.py +++ b/src/pybind/mgr/dashboard/tests/test_grafana.py @@ -11,14 +11,12 @@ from requests import RequestException from ..controllers.grafana import Grafana from ..grafana import GrafanaRestClient from ..settings import Settings -from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase, KVStoreMockMixin class GrafanaTest(ControllerTestCase, KVStoreMockMixin): @classmethod def setup_server(cls): - # pylint: disable=protected-access - Grafana._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Grafana]) def setUp(self): diff --git a/src/pybind/mgr/dashboard/tests/test_home.py b/src/pybind/mgr/dashboard/tests/test_home.py index b0641f068f3..883c6cc6a5f 100644 --- a/src/pybind/mgr/dashboard/tests/test_home.py +++ b/src/pybind/mgr/dashboard/tests/test_home.py @@ -9,7 +9,7 @@ except ImportError: from .. import mgr from ..controllers.home import HomeController, LanguageMixin -from . import ControllerTestCase, FakeFsMixin # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase, FakeFsMixin logger = logging.getLogger() diff --git a/src/pybind/mgr/dashboard/tests/test_host.py b/src/pybind/mgr/dashboard/tests/test_host.py index e15885a5695..07915aee29b 100644 --- a/src/pybind/mgr/dashboard/tests/test_host.py +++ b/src/pybind/mgr/dashboard/tests/test_host.py @@ -8,8 +8,8 @@ from orchestrator import HostSpec, InventoryHost from .. import mgr from ..controllers._version import APIVersion from ..controllers.host import Host, HostUi, get_device_osd_map, get_hosts, get_inventories +from ..tests import ControllerTestCase from ..tools import NotificationQueue, TaskManager -from . import ControllerTestCase # pylint: disable=no-name-in-module @contextlib.contextmanager @@ -44,8 +44,6 @@ class HostControllerTest(ControllerTestCase): def setup_server(cls): NotificationQueue.start_queue() TaskManager.init() - # pylint: disable=protected-access - Host._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Host]) @classmethod @@ -340,8 +338,6 @@ class HostUiControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - # pylint: disable=protected-access - HostUi._cp_config['tools.authenticate.on'] = False cls.setup_controllers([HostUi]) def test_labels(self): diff --git a/src/pybind/mgr/dashboard/tests/test_iscsi.py b/src/pybind/mgr/dashboard/tests/test_iscsi.py index addcc09a1c4..f3f786c2928 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -19,11 +19,8 @@ from ..rest_client import RequestException from ..services.exception import handle_request_error from ..services.iscsi_client import IscsiClient from ..services.orchestrator import OrchClient +from ..tests import CLICommandTestMixin, CmdException, ControllerTestCase, KVStoreMockMixin from ..tools import NotificationQueue, TaskManager -from . import CLICommandTestMixin # pylint: disable=no-name-in-module -from . import CmdException # pylint: disable=no-name-in-module -from . import ControllerTestCase # pylint: disable=no-name-in-module -from . import KVStoreMockMixin # pylint: disable=no-name-in-module class IscsiTestCli(unittest.TestCase, CLICommandTestMixin): @@ -86,9 +83,6 @@ class IscsiTestController(ControllerTestCase, KVStoreMockMixin): TaskManager.init() OrchClient.instance().available = lambda: False mgr.rados.side_effect = None - # pylint: disable=protected-access - Iscsi._cp_config['tools.authenticate.on'] = False - IscsiTarget._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Iscsi, IscsiTarget]) @classmethod @@ -752,8 +746,6 @@ class IscsiTestController(ControllerTestCase, KVStoreMockMixin): class TestIscsiUi(ControllerTestCase): @classmethod def setup_server(cls): - # pylint: disable=protected-access - IscsiUi._cp_config['tools.authenticate.on'] = False cls.setup_controllers([IscsiUi]) @mock.patch('dashboard.services.tcmu_service.TcmuService.get_image_info') diff --git a/src/pybind/mgr/dashboard/tests/test_orchestrator.py b/src/pybind/mgr/dashboard/tests/test_orchestrator.py index d9ee85cf305..ded06ba50e4 100644 --- a/src/pybind/mgr/dashboard/tests/test_orchestrator.py +++ b/src/pybind/mgr/dashboard/tests/test_orchestrator.py @@ -6,7 +6,7 @@ from orchestrator import Orchestrator as OrchestratorBase from ..controllers.orchestrator import Orchestrator from ..services.orchestrator import OrchFeature -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase class OrchestratorControllerTest(ControllerTestCase): @@ -15,8 +15,6 @@ class OrchestratorControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - # pylint: disable=protected-access - Orchestrator._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Orchestrator]) @mock.patch('dashboard.controllers.orchestrator.OrchClient.instance') diff --git a/src/pybind/mgr/dashboard/tests/test_osd.py b/src/pybind/mgr/dashboard/tests/test_osd.py index 669dd63bbf8..790c9b35926 100644 --- a/src/pybind/mgr/dashboard/tests/test_osd.py +++ b/src/pybind/mgr/dashboard/tests/test_osd.py @@ -9,8 +9,8 @@ from ceph.deployment.service_spec import PlacementSpec # type: ignore from .. import mgr from ..controllers.osd import Osd +from ..tests import ControllerTestCase from ..tools import NotificationQueue, TaskManager -from . import ControllerTestCase # pylint: disable=no-name-in-module from .helper import update_dict # pylint: disable=import-error @@ -191,7 +191,6 @@ class OsdHelper(object): class OsdTest(ControllerTestCase): @classmethod def setup_server(cls): - Osd._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access cls.setup_controllers([Osd]) NotificationQueue.start_queue() TaskManager.init() diff --git a/src/pybind/mgr/dashboard/tests/test_plugin_debug.py b/src/pybind/mgr/dashboard/tests/test_plugin_debug.py index 5010d9768ff..6f8075e4f4e 100644 --- a/src/pybind/mgr/dashboard/tests/test_plugin_debug.py +++ b/src/pybind/mgr/dashboard/tests/test_plugin_debug.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from . import CLICommandTestMixin, ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import CLICommandTestMixin, ControllerTestCase class TestPluginDebug(ControllerTestCase, CLICommandTestMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_pool.py b/src/pybind/mgr/dashboard/tests/test_pool.py index d5cdb63e0e5..02e2b641ca4 100644 --- a/src/pybind/mgr/dashboard/tests/test_pool.py +++ b/src/pybind/mgr/dashboard/tests/test_pool.py @@ -9,8 +9,8 @@ except ImportError: from ..controllers.pool import Pool from ..controllers.task import Task +from ..tests import ControllerTestCase from ..tools import NotificationQueue, TaskManager -from . import ControllerTestCase # pylint: disable=no-name-in-module class MockTask(object): @@ -23,8 +23,6 @@ class MockTask(object): class PoolControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - Task._cp_config['tools.authenticate.on'] = False - Pool._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Pool, Task]) @mock.patch('dashboard.services.progress.get_progress_tasks') diff --git a/src/pybind/mgr/dashboard/tests/test_prometheus.py b/src/pybind/mgr/dashboard/tests/test_prometheus.py index 14b2dca9ba2..cd2fb3e8dd3 100644 --- a/src/pybind/mgr/dashboard/tests/test_prometheus.py +++ b/src/pybind/mgr/dashboard/tests/test_prometheus.py @@ -7,7 +7,7 @@ except ImportError: from .. import mgr from ..controllers.prometheus import Prometheus, PrometheusNotifications, PrometheusReceiver -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase class PrometheusControllerTest(ControllerTestCase): @@ -24,8 +24,6 @@ class PrometheusControllerTest(ControllerTestCase): 'PROMETHEUS_API_HOST': cls.prometheus_host } mgr.get_module_option.side_effect = settings.get - Prometheus._cp_config['tools.authenticate.on'] = False - PrometheusNotifications._cp_config['tools.authenticate.on'] = False cls.setup_controllers([Prometheus, PrometheusNotifications, PrometheusReceiver]) def test_rules(self): diff --git a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py index 490a8a6e299..a7660475d48 100644 --- a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py @@ -14,7 +14,7 @@ from ..controllers.rbd_mirroring import RbdMirroring, \ RbdMirroringPoolBootstrap, RbdMirroringSummary, get_daemons, get_pools from ..controllers.summary import Summary from ..services import progress -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase mock_list_servers = [{ 'hostname': 'ceph-host', @@ -161,10 +161,6 @@ class RbdMirroringControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - # pylint: disable=protected-access - RbdMirroring._cp_config['tools.authenticate.on'] = False - # pylint: enable=protected-access - cls.setup_controllers([RbdMirroring]) @mock.patch('dashboard.controllers.rbd_mirroring.rbd.RBD') @@ -192,10 +188,6 @@ class RbdMirroringPoolBootstrapControllerTest(ControllerTestCase): @classmethod def setup_server(cls): - # pylint: disable=protected-access - RbdMirroringPoolBootstrap._cp_config['tools.authenticate.on'] = False - # pylint: enable=protected-access - cls.setup_controllers([RbdMirroringPoolBootstrap]) @mock.patch('dashboard.controllers.rbd_mirroring.rbd.RBD') @@ -259,11 +251,6 @@ class RbdMirroringSummaryControllerTest(ControllerTestCase): progress.get_progress_tasks = mock.MagicMock() progress.get_progress_tasks.return_value = ([], []) - # pylint: disable=protected-access - RbdMirroringSummary._cp_config['tools.authenticate.on'] = False - Summary._cp_config['tools.authenticate.on'] = False - # pylint: enable=protected-access - cls.setup_controllers([RbdMirroringSummary, Summary], '/test') @mock.patch('dashboard.controllers.rbd_mirroring.rbd.RBD') diff --git a/src/pybind/mgr/dashboard/tests/test_rest_tasks.py b/src/pybind/mgr/dashboard/tests/test_rest_tasks.py index b2bf7091f87..b320298515a 100644 --- a/src/pybind/mgr/dashboard/tests/test_rest_tasks.py +++ b/src/pybind/mgr/dashboard/tests/test_rest_tasks.py @@ -10,8 +10,8 @@ except ImportError: from ..controllers import RESTController, Router, Task from ..controllers.task import Task as TaskController from ..services import progress +from ..tests import ControllerTestCase from ..tools import NotificationQueue, TaskManager -from . import ControllerTestCase # pylint: disable=no-name-in-module @Router('/test/task', secure=False) @@ -58,8 +58,6 @@ class TaskControllerTest(ControllerTestCase): NotificationQueue.start_queue() TaskManager.init() - TaskTest._cp_config['tools.authenticate.on'] = False - TaskController._cp_config['tools.authenticate.on'] = False cls.setup_controllers([TaskTest, TaskController]) @classmethod diff --git a/src/pybind/mgr/dashboard/tests/test_rgw.py b/src/pybind/mgr/dashboard/tests/test_rgw.py index c5fb94af3d1..0f500a6545c 100644 --- a/src/pybind/mgr/dashboard/tests/test_rgw.py +++ b/src/pybind/mgr/dashboard/tests/test_rgw.py @@ -4,13 +4,12 @@ from .. import mgr from ..controllers.rgw import Rgw, RgwDaemon, RgwUser from ..rest_client import RequestException from ..services.rgw_client import RgwClient -from . import ControllerTestCase, RgwStub # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase, RgwStub class RgwControllerTestCase(ControllerTestCase): @classmethod def setup_server(cls): - Rgw._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access cls.setup_controllers([Rgw], '/test') def setUp(self) -> None: @@ -61,7 +60,6 @@ class RgwControllerTestCase(ControllerTestCase): class RgwDaemonControllerTestCase(ControllerTestCase): @classmethod def setup_server(cls): - RgwDaemon._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access cls.setup_controllers([RgwDaemon], '/test') @patch('dashboard.services.rgw_client.RgwClient._get_user_id', Mock( @@ -120,7 +118,6 @@ class RgwDaemonControllerTestCase(ControllerTestCase): class RgwUserControllerTestCase(ControllerTestCase): @classmethod def setup_server(cls): - RgwUser._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access cls.setup_controllers([RgwUser], '/test') @patch('dashboard.controllers.rgw.RgwRESTController.proxy') diff --git a/src/pybind/mgr/dashboard/tests/test_rgw_client.py b/src/pybind/mgr/dashboard/tests/test_rgw_client.py index f8a8f2f689d..d23bdec2ca5 100644 --- a/src/pybind/mgr/dashboard/tests/test_rgw_client.py +++ b/src/pybind/mgr/dashboard/tests/test_rgw_client.py @@ -9,7 +9,7 @@ from ..exceptions import DashboardException from ..services.rgw_client import NoCredentialsException, \ NoRgwDaemonsException, RgwClient, _parse_frontend_config from ..settings import Settings -from . import CLICommandTestMixin, RgwStub # pylint: disable=no-name-in-module +from ..tests import CLICommandTestMixin, RgwStub @patch('dashboard.services.rgw_client.RgwClient._get_user_id', Mock( diff --git a/src/pybind/mgr/dashboard/tests/test_settings.py b/src/pybind/mgr/dashboard/tests/test_settings.py index 049475bbf48..d6c94b6b0b8 100644 --- a/src/pybind/mgr/dashboard/tests/test_settings.py +++ b/src/pybind/mgr/dashboard/tests/test_settings.py @@ -8,7 +8,7 @@ from mgr_module import ERROR_MSG_EMPTY_INPUT_FILE from .. import settings from ..controllers.settings import Settings as SettingsController from ..settings import Settings, handle_option_command -from . import ControllerTestCase, KVStoreMockMixin # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase, KVStoreMockMixin class SettingsTest(unittest.TestCase, KVStoreMockMixin): @@ -129,9 +129,6 @@ class SettingsTest(unittest.TestCase, KVStoreMockMixin): 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 diff --git a/src/pybind/mgr/dashboard/tests/test_sso.py b/src/pybind/mgr/dashboard/tests/test_sso.py index 0aaa0e87478..e077dde19e1 100644 --- a/src/pybind/mgr/dashboard/tests/test_sso.py +++ b/src/pybind/mgr/dashboard/tests/test_sso.py @@ -6,7 +6,7 @@ import tempfile import unittest from ..services.sso import load_sso_db -from . import CLICommandTestMixin, CmdException # pylint: disable=no-name-in-module +from ..tests import CLICommandTestMixin, CmdException class AccessControlTest(unittest.TestCase, CLICommandTestMixin): diff --git a/src/pybind/mgr/dashboard/tests/test_tools.py b/src/pybind/mgr/dashboard/tests/test_tools.py index fa14195e71e..29f6123f327 100644 --- a/src/pybind/mgr/dashboard/tests/test_tools.py +++ b/src/pybind/mgr/dashboard/tests/test_tools.py @@ -13,9 +13,9 @@ except ImportError: from ..controllers import APIRouter, BaseController, Proxy, RESTController, Router from ..controllers._version import APIVersion from ..services.exception import handle_rados_error +from ..tests import ControllerTestCase from ..tools import dict_contains_path, dict_get, json_str_to_object, \ merge_list_of_dicts_by_key, partial_dict -from . import ControllerTestCase # pylint: disable=no-name-in-module # pylint: disable=W0613 diff --git a/src/pybind/mgr/dashboard/tests/test_versioning.py b/src/pybind/mgr/dashboard/tests/test_versioning.py index 85804b00ba2..0fc4b9336b0 100644 --- a/src/pybind/mgr/dashboard/tests/test_versioning.py +++ b/src/pybind/mgr/dashboard/tests/test_versioning.py @@ -5,7 +5,7 @@ import unittest from ..controllers._api_router import APIRouter from ..controllers._rest_controller import RESTController from ..controllers._version import APIVersion -from . import ControllerTestCase # pylint: disable=no-name-in-module +from ..tests import ControllerTestCase @APIRouter("/vtest", secure=False) -- 2.39.5