Add toggle 'dashed' to 'generate_uuid' function
Enable 'generate_uuid' function to generate uuid with dashes or not, because some projects use uuid with dashes while some others not. Change-Id: I6f213ea47de5713a79b5e0dccf486a7bba88f853
This commit is contained in:
parent
856ffc7e9a
commit
0e99039d42
@ -29,6 +29,12 @@ class UUIDUtilsTest(test_base.BaseTestCase):
|
|||||||
# make sure there are 4 dashes
|
# make sure there are 4 dashes
|
||||||
self.assertEqual(len(uuid_string.replace('-', '')), 32)
|
self.assertEqual(len(uuid_string.replace('-', '')), 32)
|
||||||
|
|
||||||
|
def test_generate_uuid_dashed_false(self):
|
||||||
|
uuid_string = uuidutils.generate_uuid(dashed=False)
|
||||||
|
self.assertIsInstance(uuid_string, str)
|
||||||
|
self.assertEqual(len(uuid_string), 32)
|
||||||
|
self.assertFalse('-' in uuid_string)
|
||||||
|
|
||||||
def test_is_uuid_like(self):
|
def test_is_uuid_like(self):
|
||||||
self.assertTrue(uuidutils.is_uuid_like(str(uuid.uuid4())))
|
self.assertTrue(uuidutils.is_uuid_like(str(uuid.uuid4())))
|
||||||
self.assertTrue(uuidutils.is_uuid_like(
|
self.assertTrue(uuidutils.is_uuid_like(
|
||||||
|
@ -22,12 +22,16 @@ UUID related utilities and helper functions.
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
def generate_uuid():
|
def generate_uuid(dashed=True):
|
||||||
"""Creates a random uuid string.
|
"""Creates a random uuid string.
|
||||||
|
|
||||||
|
:param dashed: Generate uuid with dashes or not
|
||||||
|
:type dashed: bool
|
||||||
:returns: string
|
:returns: string
|
||||||
"""
|
"""
|
||||||
return str(uuid.uuid4())
|
if dashed:
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
return uuid.uuid4().hex
|
||||||
|
|
||||||
|
|
||||||
def _format_uuid_string(string):
|
def _format_uuid_string(string):
|
||||||
|
Loading…
Reference in New Issue
Block a user