From: Alfonso Martínez Date: Wed, 3 Nov 2021 09:17:21 +0000 (+0100) Subject: mgr/dashboard: python unit tests refactoring X-Git-Tag: v16.2.7~52^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8cf2ca8a998e2ef9419a834e9154a0993205c293;p=ceph.git mgr/dashboard: python unit tests refactoring * 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 (cherry picked from commit a6aeded5141ec3a959a86aa4002ccf5ac8d0a523) Conflicts: src/pybind/mgr/dashboard/tests/test_docs.py - Resolved conflicts. src/pybind/mgr/dashboard/tests/test_iscsi.py - Resolved conflicts. --- diff --git a/doc/dev/developer_guide/dash-devel.rst b/doc/dev/developer_guide/dash-devel.rst index 94e877e03d2a..5b449e099b96 100644 --- a/doc/dev/developer_guide/dash-devel.rst +++ b/doc/dev/developer_guide/dash-devel.rst @@ -1659,8 +1659,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") @@ -1670,8 +1670,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 cda766009397..ba005c480d52 100644 --- a/src/pybind/mgr/dashboard/tests/__init__.py +++ b/src/pybind/mgr/dashboard/tests/__init__.py @@ -6,6 +6,7 @@ import json import logging import threading import time +from typing import Any, Dict from unittest.mock import Mock import cherrypy @@ -102,12 +103,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 f64664caa400..7a75bda6dd35 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 d54e33ee02cd..854d76468c21 100644 --- a/src/pybind/mgr/dashboard/tests/test_api_auditing.py +++ b/src/pybind/mgr/dashboard/tests/test_api_auditing.py @@ -11,7 +11,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 6f1d2a084ec4..698db40e1e5e 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 5c35cab329cd..ae4253543841 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 4fde5452a6bd..4b91b110391e 100644 --- a/src/pybind/mgr/dashboard/tests/test_controllers.py +++ b/src/pybind/mgr/dashboard/tests/test_controllers.py @@ -2,7 +2,7 @@ from __future__ import absolute_import 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 d0529ab8d823..5291edb3bb77 100644 --- a/src/pybind/mgr/dashboard/tests/test_docs.py +++ b/src/pybind/mgr/dashboard/tests/test_docs.py @@ -2,10 +2,10 @@ from __future__ import absolute_import 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 @@ -66,6 +66,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): @@ -120,5 +121,5 @@ 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) 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 8ff1490708ff..d1b032a514f3 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 0805e8c7bd1a..2a9e840b8987 100644 --- a/src/pybind/mgr/dashboard/tests/test_exceptions.py +++ b/src/pybind/mgr/dashboard/tests/test_exceptions.py @@ -9,8 +9,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 d908c0e577da..dcc41b25eb10 100644 --- a/src/pybind/mgr/dashboard/tests/test_feature_toggles.py +++ b/src/pybind/mgr/dashboard/tests/test_feature_toggles.py @@ -9,7 +9,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 d9b15e8231e5..f54219c9f132 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 1b1b6b706390..0b788626048d 100644 --- a/src/pybind/mgr/dashboard/tests/test_home.py +++ b/src/pybind/mgr/dashboard/tests/test_home.py @@ -10,7 +10,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 e15885a56951..07915aee29b2 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 4060c6c4a044..7728a496b9eb 100644 --- a/src/pybind/mgr/dashboard/tests/test_iscsi.py +++ b/src/pybind/mgr/dashboard/tests/test_iscsi.py @@ -17,11 +17,8 @@ from ..controllers.iscsi import Iscsi, IscsiTarget from ..rest_client import RequestException 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): @@ -84,9 +81,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 diff --git a/src/pybind/mgr/dashboard/tests/test_orchestrator.py b/src/pybind/mgr/dashboard/tests/test_orchestrator.py index d9ee85cf3053..ded06ba50e49 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 669dd63bbf8b..790c9b359262 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 cb4d1afc2184..572f82a41618 100644 --- a/src/pybind/mgr/dashboard/tests/test_plugin_debug.py +++ b/src/pybind/mgr/dashboard/tests/test_plugin_debug.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import -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 d5cdb63e0e5c..02e2b641ca47 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 14b2dca9ba25..cd2fb3e8dd39 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 9f83bad83e12..e064089706a6 100644 --- a/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/tests/test_rbd_mirroring.py @@ -11,7 +11,7 @@ from .. import mgr from ..controllers.rbd_mirroring import RbdMirroring, RbdMirroringPoolBootstrap, RbdMirroringSummary 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', @@ -51,10 +51,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') @@ -82,10 +78,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') @@ -149,11 +141,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 b2bf7091f87b..b320298515ac 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 c5fb94af3d1f..0f500a6545cd 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 f8a8f2f689d2..d23bdec2ca51 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 6e382b9d40f7..e204b566ab50 100644 --- a/src/pybind/mgr/dashboard/tests/test_settings.py +++ b/src/pybind/mgr/dashboard/tests/test_settings.py @@ -9,7 +9,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): @@ -130,9 +130,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 ab565137a18f..5594738d173b 100644 --- a/src/pybind/mgr/dashboard/tests/test_sso.py +++ b/src/pybind/mgr/dashboard/tests/test_sso.py @@ -6,7 +6,7 @@ import errno 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 b30ab0c90b4f..eaae3e2959e0 100644 --- a/src/pybind/mgr/dashboard/tests/test_tools.py +++ b/src/pybind/mgr/dashboard/tests/test_tools.py @@ -14,9 +14,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 48e6394c2cf0..0a77a299e98d 100644 --- a/src/pybind/mgr/dashboard/tests/test_versioning.py +++ b/src/pybind/mgr/dashboard/tests/test_versioning.py @@ -6,7 +6,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)