Fix H202 assertRaises Exception

Align the hacking version between test-requirement and global requirement.

The change of H202 detection from 0.6 to 0.7 in hacking is:

-    if logical_line.startswith("self.assertRaises(Exception)"):
+    if logical_line.startswith("self.assertRaises(Exception,"):

then more cases are detected by this change. Fix the exposed H202 error.

There is a special test case:
tests/v3/test_endpoints.py:test_update_invalid_interface

ref = self.new_ref(interface=uuid.uuid4().hex)

this line can not generate proper parameter for self.manager.update,
add a parameter "endpoint" for it, according to the
definition in keystoneclient/v3/endpoints.py:EndpointManager.update.

Otherwise, there will be following error after changing the Exception
to exceptions.ValidationError:
TypeError: update() takes at least 2 arguments (6 given)

Fixes Bug #1220008

Change-Id: I8f7ed7a6eebf8576a6db5fecd86b9d19a15c8d60
This commit is contained in:
Kui Shi
2013-10-04 16:54:03 +08:00
parent 0341f933ca
commit 8a036c3f76
5 changed files with 23 additions and 15 deletions

View File

@@ -439,11 +439,12 @@ class AuthProtocol(object):
def _assert_valid_memcache_protection_config(self):
if self._memcache_security_strategy:
if self._memcache_security_strategy not in ('MAC', 'ENCRYPT'):
raise Exception('memcache_security_strategy must be '
raise ConfigurationError('memcache_security_strategy must be '
'ENCRYPT or MAC')
if not self._memcache_secret_key:
raise Exception('mecmache_secret_key must be defined when '
'a memcache_security_strategy is defined')
raise ConfigurationError('mecmache_secret_key must be defined '
'when a memcache_security_strategy '
'is defined')
def _init_cache(self, env):
cache = self._conf_get('cache')

View File

@@ -751,31 +751,36 @@ class CommonAuthTokenMiddlewareTest(object):
'memcached_servers': ['localhost:11211'],
'memcache_security_strategy': 'Encrypt'
}
self.assertRaises(Exception, self.set_middleware, conf=conf)
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
conf=conf)
# test invalue memcache_security_strategy
conf = {
'memcached_servers': ['localhost:11211'],
'memcache_security_strategy': 'whatever'
}
self.assertRaises(Exception, self.set_middleware, conf=conf)
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
conf=conf)
# test missing memcache_secret_key
conf = {
'memcached_servers': ['localhost:11211'],
'memcache_security_strategy': 'mac'
}
self.assertRaises(Exception, self.set_middleware, conf=conf)
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
conf=conf)
conf = {
'memcached_servers': ['localhost:11211'],
'memcache_security_strategy': 'Encrypt',
'memcache_secret_key': ''
}
self.assertRaises(Exception, self.set_middleware, conf=conf)
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
conf=conf)
conf = {
'memcached_servers': ['localhost:11211'],
'memcache_security_strategy': 'mAc',
'memcache_secret_key': ''
}
self.assertRaises(Exception, self.set_middleware, conf=conf)
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
conf=conf)
def test_config_revocation_cache_timeout(self):
conf = {

View File

@@ -14,6 +14,7 @@
import uuid
from keystoneclient import exceptions
from keystoneclient.tests.v3 import utils
from keystoneclient.v3 import endpoints
@@ -49,7 +50,7 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
def test_create_invalid_interface(self):
ref = self.new_ref(interface=uuid.uuid4().hex)
self.assertRaises(Exception, self.manager.create,
self.assertRaises(exceptions.ValidationError, self.manager.create,
**utils.parameterize(ref))
def test_update_public_interface(self):
@@ -66,7 +67,8 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
def test_update_invalid_interface(self):
ref = self.new_ref(interface=uuid.uuid4().hex)
self.assertRaises(Exception, self.manager.update,
ref['endpoint'] = "fake_endpoint"
self.assertRaises(exceptions.ValidationError, self.manager.update,
**utils.parameterize(ref))
def test_list_public_interface(self):
@@ -87,5 +89,5 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
def test_list_invalid_interface(self):
interface = uuid.uuid4().hex
expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
self.assertRaises(Exception, self.manager.list,
self.assertRaises(exceptions.ValidationError, self.manager.list,
expected_path=expected_path, interface=interface)

View File

@@ -15,6 +15,7 @@
# under the License.
from keystoneclient import base
from keystoneclient import exceptions
VALID_INTERFACES = ['public', 'admin', 'internal']
@@ -45,7 +46,7 @@ class EndpointManager(base.CrudManager):
if interface is not None and interface not in VALID_INTERFACES:
msg = '"interface" must be one of: %s'
msg = msg % ', '.join(VALID_INTERFACES)
raise Exception(msg)
raise exceptions.ValidationError(msg)
def create(self, service, url, interface=None, region=None, enabled=True,
**kwargs):

View File

@@ -27,9 +27,8 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
downloadcache = ~/cache/pip
[flake8]
# H202: assertRaises Exception too broad
# F821: undefined name
# H304: no relative imports
ignore = F821,H202,H304
ignore = F821,H304
show-source = True
exclude = .venv,.tox,dist,doc,*egg,build