Merge "Fix H202 assertRaises Exception"
This commit is contained in:
@@ -462,11 +462,12 @@ class AuthProtocol(object):
|
|||||||
def _assert_valid_memcache_protection_config(self):
|
def _assert_valid_memcache_protection_config(self):
|
||||||
if self._memcache_security_strategy:
|
if self._memcache_security_strategy:
|
||||||
if self._memcache_security_strategy not in ('MAC', 'ENCRYPT'):
|
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')
|
'ENCRYPT or MAC')
|
||||||
if not self._memcache_secret_key:
|
if not self._memcache_secret_key:
|
||||||
raise Exception('mecmache_secret_key must be defined when '
|
raise ConfigurationError('mecmache_secret_key must be defined '
|
||||||
'a memcache_security_strategy is defined')
|
'when a memcache_security_strategy '
|
||||||
|
'is defined')
|
||||||
|
|
||||||
def _init_cache(self, env):
|
def _init_cache(self, env):
|
||||||
cache = self._conf_get('cache')
|
cache = self._conf_get('cache')
|
||||||
|
@@ -771,31 +771,36 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
'memcached_servers': ['localhost:11211'],
|
'memcached_servers': ['localhost:11211'],
|
||||||
'memcache_security_strategy': 'Encrypt'
|
'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
|
# test invalue memcache_security_strategy
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': ['localhost:11211'],
|
'memcached_servers': ['localhost:11211'],
|
||||||
'memcache_security_strategy': 'whatever'
|
'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
|
# test missing memcache_secret_key
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': ['localhost:11211'],
|
'memcached_servers': ['localhost:11211'],
|
||||||
'memcache_security_strategy': 'mac'
|
'memcache_security_strategy': 'mac'
|
||||||
}
|
}
|
||||||
self.assertRaises(Exception, self.set_middleware, conf=conf)
|
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
|
||||||
|
conf=conf)
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': ['localhost:11211'],
|
'memcached_servers': ['localhost:11211'],
|
||||||
'memcache_security_strategy': 'Encrypt',
|
'memcache_security_strategy': 'Encrypt',
|
||||||
'memcache_secret_key': ''
|
'memcache_secret_key': ''
|
||||||
}
|
}
|
||||||
self.assertRaises(Exception, self.set_middleware, conf=conf)
|
self.assertRaises(auth_token.ConfigurationError, self.set_middleware,
|
||||||
|
conf=conf)
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': ['localhost:11211'],
|
'memcached_servers': ['localhost:11211'],
|
||||||
'memcache_security_strategy': 'mAc',
|
'memcache_security_strategy': 'mAc',
|
||||||
'memcache_secret_key': ''
|
'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):
|
def test_config_revocation_cache_timeout(self):
|
||||||
conf = {
|
conf = {
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import endpoints
|
from keystoneclient.v3 import endpoints
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
def test_create_invalid_interface(self):
|
def test_create_invalid_interface(self):
|
||||||
ref = self.new_ref(interface=uuid.uuid4().hex)
|
ref = self.new_ref(interface=uuid.uuid4().hex)
|
||||||
self.assertRaises(Exception, self.manager.create,
|
self.assertRaises(exceptions.ValidationError, self.manager.create,
|
||||||
**utils.parameterize(ref))
|
**utils.parameterize(ref))
|
||||||
|
|
||||||
def test_update_public_interface(self):
|
def test_update_public_interface(self):
|
||||||
@@ -66,7 +67,8 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
def test_update_invalid_interface(self):
|
def test_update_invalid_interface(self):
|
||||||
ref = self.new_ref(interface=uuid.uuid4().hex)
|
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))
|
**utils.parameterize(ref))
|
||||||
|
|
||||||
def test_list_public_interface(self):
|
def test_list_public_interface(self):
|
||||||
@@ -87,5 +89,5 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
|
|||||||
def test_list_invalid_interface(self):
|
def test_list_invalid_interface(self):
|
||||||
interface = uuid.uuid4().hex
|
interface = uuid.uuid4().hex
|
||||||
expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
|
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)
|
expected_path=expected_path, interface=interface)
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from keystoneclient import base
|
from keystoneclient import base
|
||||||
|
from keystoneclient import exceptions
|
||||||
|
|
||||||
|
|
||||||
VALID_INTERFACES = ['public', 'admin', 'internal']
|
VALID_INTERFACES = ['public', 'admin', 'internal']
|
||||||
@@ -45,7 +46,7 @@ class EndpointManager(base.CrudManager):
|
|||||||
if interface is not None and interface not in VALID_INTERFACES:
|
if interface is not None and interface not in VALID_INTERFACES:
|
||||||
msg = '"interface" must be one of: %s'
|
msg = '"interface" must be one of: %s'
|
||||||
msg = msg % ', '.join(VALID_INTERFACES)
|
msg = msg % ', '.join(VALID_INTERFACES)
|
||||||
raise Exception(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
|
||||||
def create(self, service, url, interface=None, region=None, enabled=True,
|
def create(self, service, url, interface=None, region=None, enabled=True,
|
||||||
**kwargs):
|
**kwargs):
|
||||||
|
3
tox.ini
3
tox.ini
@@ -27,9 +27,8 @@ commands = python setup.py testr --coverage --testr-args='{posargs}'
|
|||||||
downloadcache = ~/cache/pip
|
downloadcache = ~/cache/pip
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
# H202: assertRaises Exception too broad
|
|
||||||
# F821: undefined name
|
# F821: undefined name
|
||||||
# H304: no relative imports
|
# H304: no relative imports
|
||||||
ignore = F821,H202,H304
|
ignore = F821,H304
|
||||||
show-source = True
|
show-source = True
|
||||||
exclude = .venv,.tox,dist,doc,*egg,build
|
exclude = .venv,.tox,dist,doc,*egg,build
|
||||||
|
Reference in New Issue
Block a user