Merge "Use check_string_length from oslo_utils"
This commit is contained in:
commit
809340bcf3
@ -813,6 +813,9 @@ class StringLengthTestCase(test.TestCase):
|
||||
self.assertRaises(exception.InvalidInput,
|
||||
utils.check_string_length,
|
||||
'a' * 256, 'name', max_length=255)
|
||||
self.assertRaises(exception.InvalidInput,
|
||||
utils.check_string_length,
|
||||
dict(), 'name', max_length=255)
|
||||
|
||||
|
||||
class AddVisibleAdminMetadataTestCase(test.TestCase):
|
||||
|
@ -633,19 +633,12 @@ def check_string_length(value, name, 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):
|
||||
msg = _("%s is not a string or unicode") % name
|
||||
raise exception.InvalidInput(message=msg)
|
||||
|
||||
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(reason=exc)
|
||||
|
||||
_visible_admin_metadata_keys = ['readonly', 'attached_mode']
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user