Enforce autospec in some api tests

And remove corresping filters.

Change-Id: Idb7fe3fc8b220f223d137eaced47a9ded13eba13
This commit is contained in:
Riccardo Pittau 2020-07-16 16:26:57 +02:00
parent 15d30adc33
commit 7a839569aa
7 changed files with 16 additions and 14 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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'}

View File

@ -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()

View File

@ -130,7 +130,7 @@ enable-extensions=H106,H203,H204,H205,H210,H904
per-file-ignores =
ironic/cmd/__init__.py:E402
ironic/tests/base.py:E402
ironic/tests/unit/api/*:H210
ironic/tests/unit/api/controllers/*:H210
ironic/tests/unit/common/*:H210
ironic/tests/unit/drivers/modules/test_console_utils.py:H210
ironic/tests/unit/drivers/modules/test_iscsi_deploy.py:H210