[flake8] Enable extra, optional hacking checks
Update test-requirements.txt to use latest version of: * hacking Enable the following off-by-default checks: * [H203] Use assertIs(Not)None to check for None. * [H204] Use assert(Not)Equal to check for equality. * [H205] Use assert(Greater|Less)(Equal) for comparison. * [H210] Require ‘autospec’, ‘spec’, or ‘spec_set’ in mock.patch/mock.patch.object calls * [H904] Delay string interpolations at logging calls. Made necessary unit test changes to work with these checks. Change-Id: I9db3445caa2883563fd7271d6bf0b24800e06c01
This commit is contained in:
parent
f7e74ac95c
commit
b18a3f6524
|
@ -18,10 +18,12 @@ from __future__ import absolute_import
|
|||
|
||||
import fixtures
|
||||
import mock
|
||||
import time
|
||||
|
||||
from tempest import clients
|
||||
from tempest.common import credentials_factory as credentials
|
||||
from tempest import config
|
||||
from tempest import test
|
||||
|
||||
from patrole_tempest_plugin import rbac_utils
|
||||
|
||||
|
@ -73,13 +75,19 @@ class RbacUtilsFixture(fixtures.Fixture):
|
|||
'os_primary.credentials.project_id': self.PROJECT_ID,
|
||||
'get_identity_version.return_value': 'v3'
|
||||
}
|
||||
self.mock_test_obj = mock.Mock(__name__='foo', **test_obj_kwargs)
|
||||
self.mock_test_obj = mock.Mock(
|
||||
__name__='patrole_unit_test', spec=test.BaseTestCase,
|
||||
os_primary=mock.Mock(), **test_obj_kwargs)
|
||||
|
||||
# Mock out functionality that can't be used by unit tests.
|
||||
self.mock_time = mock.patch.object(rbac_utils, 'time').start()
|
||||
mock.patch.object(
|
||||
credentials, 'get_configured_admin_credentials').start()
|
||||
mock_admin_mgr = mock.patch.object(clients, 'Manager').start()
|
||||
# Mock out functionality that can't be used by unit tests. Mocking out
|
||||
# time.sleep is a test optimization.
|
||||
self.mock_time = mock.patch.object(
|
||||
rbac_utils, 'time', __name__='mock_time', spec=time).start()
|
||||
mock.patch.object(credentials, 'get_configured_admin_credentials',
|
||||
spec=object).start()
|
||||
mock_admin_mgr = mock.patch.object(
|
||||
clients, 'Manager', spec=clients.Manager,
|
||||
roles_v3_client=mock.Mock(), roles_client=mock.Mock()).start()
|
||||
self.roles_v3_client = mock_admin_mgr.return_value.roles_v3_client
|
||||
|
||||
self.set_roles(['admin', 'member'], [])
|
||||
|
|
|
@ -499,7 +499,8 @@ class PolicyAuthorityTest(base.TestCase):
|
|||
|
||||
def _test_validate_service(self, v2_services, v3_services,
|
||||
expected_failure=False, expected_services=None):
|
||||
with mock.patch.object(policy_authority, 'clients') as m_creds:
|
||||
with mock.patch.object(
|
||||
policy_authority, 'clients', autospec=True) as m_creds:
|
||||
m_creds.Manager().identity_services_client.list_services.\
|
||||
return_value = v2_services
|
||||
m_creds.Manager().identity_services_v3_client.list_services.\
|
||||
|
|
|
@ -42,9 +42,9 @@ class RBACRuleValidationTest(base.TestCase):
|
|||
|
||||
self.useFixture(
|
||||
fixtures.ConfPatcher(rbac_test_role='Member', group='patrole'))
|
||||
|
||||
# Mock the RBAC log so that it is not written to for any unit tests.
|
||||
mock.patch.object(rbac_rv.RBACLOG, 'info').start()
|
||||
# Disable patrole log for unit tests.
|
||||
self.useFixture(
|
||||
fixtures.ConfPatcher(enable_reporting=False, group='patrole_log'))
|
||||
|
||||
@mock.patch.object(rbac_rv, 'LOG', autospec=True)
|
||||
@mock.patch.object(rbac_rv, 'policy_authority', autospec=True)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
|
||||
hacking>=1.0.0 # Apache-2.0
|
||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
oslo.log>=3.30.0 # Apache-2.0
|
||||
oslo.config>=4.6.0 # Apache-2.0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# The order of packages is significant, because pip processes them in the order
|
||||
# of appearance. Changing the order has an impact on the overall integration
|
||||
# process, which may cause wedges in the gate later.
|
||||
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
|
||||
hacking>=1.0.0 # Apache-2.0
|
||||
|
||||
sphinx>=1.6.2 # BSD
|
||||
openstackdocstheme>=1.17.0 # Apache-2.0
|
||||
|
|
8
tox.ini
8
tox.ini
|
@ -56,7 +56,13 @@ commands =
|
|||
commands = oslo_debug_helper -t patrole_tempest_plugin/tests {posargs}
|
||||
|
||||
[flake8]
|
||||
enable-extensions = H106,H203,H904
|
||||
# [H106] Don’t put vim configuration in source files.
|
||||
# [H203] Use assertIs(Not)None to check for None.
|
||||
# [H204] Use assert(Not)Equal to check for equality.
|
||||
# [H205] Use assert(Greater|Less)(Equal) for comparison.
|
||||
# [H210] Require ‘autospec’, ‘spec’, or ‘spec_set’ in mock.patch/mock.patch.object calls
|
||||
# [H904] Delay string interpolations at logging calls.
|
||||
enable-extensions = H106,H203,H204,H205,H210,H904
|
||||
show-source = True
|
||||
# E123, E125 skipped as they are invalid PEP-8.
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue