Use check_string_length from oslo_utils
This patch removes code from check_string_length method in utils.py and makes call to check_string_length method from oslo_utils.strutils. TrivialFix Change-Id: Ic557270e5ca73a8a6be41814150d302541334a9c
This commit is contained in:
committed by
ChangBo Guo(gcb)
parent
3ed7da92bb
commit
ad0510c2e8
@@ -192,8 +192,8 @@ class TestSecurityGroupsV21(test.TestCase):
|
||||
self.controller.create(self.req, {'security_group': sg})
|
||||
self.fail('Should have raised BadRequest exception')
|
||||
except webob.exc.HTTPBadRequest as exc:
|
||||
self.assertEqual('description has a minimum character requirement'
|
||||
' of 1.', exc.explanation)
|
||||
self.assertEqual('description has 0 characters, '
|
||||
'less than 1.', exc.explanation)
|
||||
except exception.InvalidInput:
|
||||
self.fail('Should have raised BadRequest exception instead of')
|
||||
|
||||
|
||||
@@ -829,25 +829,12 @@ def check_string_length(value, name=None, min_length=0, max_length=None):
|
||||
:param min_length: the min_length of the string
|
||||
:param max_length: the max_length of the string
|
||||
"""
|
||||
if not isinstance(value, six.string_types):
|
||||
if name is None:
|
||||
msg = _("The input is not a string or unicode")
|
||||
else:
|
||||
msg = _("%s is not a string or unicode") % name
|
||||
raise exception.InvalidInput(message=msg)
|
||||
|
||||
if name is None:
|
||||
name = value
|
||||
|
||||
if len(value) < min_length:
|
||||
msg = _("%(name)s has a minimum character requirement of "
|
||||
"%(min_length)s.") % {'name': name, 'min_length': min_length}
|
||||
raise exception.InvalidInput(message=msg)
|
||||
|
||||
if max_length and len(value) > max_length:
|
||||
msg = _("%(name)s has more than %(max_length)s "
|
||||
"characters.") % {'name': name, 'max_length': max_length}
|
||||
raise exception.InvalidInput(message=msg)
|
||||
try:
|
||||
strutils.check_string_length(value, name=name,
|
||||
min_length=min_length,
|
||||
max_length=max_length)
|
||||
except (ValueError, TypeError) as exc:
|
||||
raise exception.InvalidInput(message=exc.args[0])
|
||||
|
||||
|
||||
def validate_integer(value, name, min_value=None, max_value=None):
|
||||
|
||||
Reference in New Issue
Block a user