Adds tests for attribute._validate_uuid

Removed redundant condition in _validate_uuid logic
Wrote test cases accordingly

Change-Id: I6ee83bda90cdfeaeaa17da6241f2673d0959baa2
This commit is contained in:
Zhongyue Luo 2012-11-12 16:18:21 +08:00
parent cf79fd37a4
commit cd1dfc2ce7
2 changed files with 9 additions and 4 deletions

View File

@ -246,10 +246,8 @@ def _validate_regex(data, valid_values=None):
def _validate_uuid(data, valid_values=None):
if uuidutils.is_uuid_like(data):
return
else:
msg = _("%s is not a valid UUID") % data
if not uuidutils.is_uuid_like(data):
msg = _("'%s' is not a valid UUID") % data
LOG.debug("validate_uuid: %s", msg)
return msg

View File

@ -255,6 +255,13 @@ class TestAttributes(unittest2.TestCase):
error = "'%s' is not a valid IP subnet" % cidr
self.assertEquals(msg, error)
def test_uuid(self):
msg = attributes._validate_uuid('true')
self.assertEquals(msg, "'true' is not a valid UUID")
msg = attributes._validate_uuid('00000000-ffff-ffff-ffff-000000000000')
self.assertIsNone(msg)
class TestConvertToBoolean(unittest2.TestCase):