From 7a839569aa5762f70a6a3975d8017fd98145242c Mon Sep 17 00:00:00 2001 From: Riccardo Pittau Date: Thu, 16 Jul 2020 16:26:57 +0200 Subject: Enforce autospec in some api tests And remove corresping filters. Change-Id: Idb7fe3fc8b220f223d137eaced47a9ded13eba13 --- ironic/tests/unit/api/base.py | 3 ++- ironic/tests/unit/api/controllers/v1/test_root.py | 1 + ironic/tests/unit/api/test_audit.py | 6 +++--- ironic/tests/unit/api/test_healthcheck.py | 4 ++-- ironic/tests/unit/api/test_hooks.py | 10 +++++----- ironic/tests/unit/api/test_ospmiddleware.py | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) (limited to 'ironic/tests') diff --git a/ironic/tests/unit/api/base.py b/ironic/tests/unit/api/base.py index 180f363e6..3d80ee42f 100644 --- a/ironic/tests/unit/api/base.py +++ b/ironic/tests/unit/api/base.py @@ -60,7 +60,8 @@ class BaseApiTest(db_base.DbTestCase): self.addCleanup(reset_pecan) - p = mock.patch('ironic.api.controllers.v1.Controller._check_version') + p = mock.patch('ironic.api.controllers.v1.Controller._check_version', + autospec=True) self._check_version = p.start() self.addCleanup(p.stop) diff --git a/ironic/tests/unit/api/controllers/v1/test_root.py b/ironic/tests/unit/api/controllers/v1/test_root.py index 3d8408f1c..b3e58b817 100644 --- a/ironic/tests/unit/api/controllers/v1/test_root.py +++ b/ironic/tests/unit/api/controllers/v1/test_root.py @@ -25,6 +25,7 @@ class TestV1Routing(api_base.BaseApiTest): def test_route_checks_version(self): self.get_json('/') self._check_version.assert_called_once_with(mock.ANY, + mock.ANY, mock.ANY) diff --git a/ironic/tests/unit/api/test_audit.py b/ironic/tests/unit/api/test_audit.py index 34ecaf18f..d85ed3e85 100644 --- a/ironic/tests/unit/api/test_audit.py +++ b/ironic/tests/unit/api/test_audit.py @@ -33,7 +33,7 @@ class TestAuditMiddleware(base.BaseApiTest): the test suite in keystone audit_middleware. """ - @mock.patch.object(audit, 'AuditMiddleware') + @mock.patch.object(audit, 'AuditMiddleware', autospec=True) def test_enable_audit_request(self, mock_audit): CONF.audit.enabled = True self._make_app() @@ -42,7 +42,7 @@ class TestAuditMiddleware(base.BaseApiTest): audit_map_file=CONF.audit.audit_map_file, ignore_req_list=CONF.audit.ignore_req_list) - @mock.patch.object(audit, 'AuditMiddleware') + @mock.patch.object(audit, 'AuditMiddleware', autospec=True) def test_enable_audit_request_error(self, mock_audit): CONF.audit.enabled = True mock_audit.side_effect = IOError("file access error") @@ -50,7 +50,7 @@ class TestAuditMiddleware(base.BaseApiTest): self.assertRaises(exception.InputFileError, self._make_app) - @mock.patch.object(audit, 'AuditMiddleware') + @mock.patch.object(audit, 'AuditMiddleware', autospec=True) def test_disable_audit_request(self, mock_audit): CONF.audit.enabled = False self._make_app() diff --git a/ironic/tests/unit/api/test_healthcheck.py b/ironic/tests/unit/api/test_healthcheck.py index 907bc9f4a..2b7e4bad8 100644 --- a/ironic/tests/unit/api/test_healthcheck.py +++ b/ironic/tests/unit/api/test_healthcheck.py @@ -27,13 +27,13 @@ CONF = cfg.CONF class TestHealthcheckMiddleware(base.BaseApiTest): """Provide a basic smoke test to ensure healthcheck middleware works.""" - @mock.patch.object(healthcheck, 'Healthcheck') + @mock.patch.object(healthcheck, 'Healthcheck', autospec=True) def test_enable(self, mock_healthcheck): CONF.set_override('enabled', True, group='healthcheck') self._make_app() mock_healthcheck.assert_called_once_with(mock.ANY, CONF) - @mock.patch.object(healthcheck, 'Healthcheck') + @mock.patch.object(healthcheck, 'Healthcheck', autospec=True) def test_disable(self, mock_healthcheck): CONF.set_override('enabled', False, group='healthcheck') self._make_app() diff --git a/ironic/tests/unit/api/test_hooks.py b/ironic/tests/unit/api/test_hooks.py index f5e8db3b6..45058bbe4 100644 --- a/ironic/tests/unit/api/test_hooks.py +++ b/ironic/tests/unit/api/test_hooks.py @@ -103,7 +103,7 @@ class TestNoExceptionTracebackHook(base.BaseApiTest): def setUp(self): super(TestNoExceptionTracebackHook, self).setUp() - p = mock.patch.object(root, 'root') + p = mock.patch.object(root, 'root', autospec=True) self.root_convert_mock = p.start() self.addCleanup(p.stop) @@ -204,8 +204,8 @@ class TestNoExceptionTracebackHook(base.BaseApiTest): class TestContextHook(base.BaseApiTest): - @mock.patch.object(context, 'RequestContext') - @mock.patch.object(policy, 'check') + @mock.patch.object(context, 'RequestContext', autospec=True) + @mock.patch.object(policy, 'check', autospec=True) def _test_context_hook(self, mock_policy, mock_ctx, is_admin=False, is_public_api=False, auth_strategy='keystone', request_id=None): @@ -260,8 +260,8 @@ class TestContextHook(base.BaseApiTest): class TestPolicyDeprecation(tests_base.TestCase): @mock.patch.object(hooks, 'CHECKED_DEPRECATED_POLICY_ARGS', False) - @mock.patch.object(hooks.LOG, 'warning') - @mock.patch.object(policy, 'get_enforcer') + @mock.patch.object(hooks.LOG, 'warning', autospec=True) + @mock.patch.object(policy, 'get_enforcer', autospec=True) def test_policy_deprecation_check(self, enforcer_mock, warning_mock): rules = {'is_member': 'project_name:demo or tenant:baremetal', 'is_default_project_domain': 'project_domain_id:default'} diff --git a/ironic/tests/unit/api/test_ospmiddleware.py b/ironic/tests/unit/api/test_ospmiddleware.py index 856ba8380..555251dd7 100644 --- a/ironic/tests/unit/api/test_ospmiddleware.py +++ b/ironic/tests/unit/api/test_ospmiddleware.py @@ -30,13 +30,13 @@ class TestOsprofilerWsgiMiddleware(base.BaseApiTest): def setUp(self): super(TestOsprofilerWsgiMiddleware, self).setUp() - @mock.patch.object(web, 'WsgiMiddleware') + @mock.patch.object(web, 'WsgiMiddleware', autospec=True) def test_enable_osp_wsgi_request(self, mock_ospmiddleware): CONF.profiler.enabled = True self._make_app() mock_ospmiddleware.assert_called_once_with(mock.ANY) - @mock.patch.object(web, 'WsgiMiddleware') + @mock.patch.object(web, 'WsgiMiddleware', autospec=True) def test_disable_osp_wsgi_request(self, mock_ospmiddleware): CONF.profiler.enabled = False self._make_app() -- cgit v1.2.1