Add a doc and test for data_utils.rand_password
This commit adds a documentation and a test about the length parameter to data_utils.rand_password to clarify the behavior. Change-Id: I26c7380d1430f107c0aaf705d160d8782b850438
This commit is contained in:
@@ -61,6 +61,7 @@ def rand_password(length=15):
|
||||
"""Generate a random password
|
||||
|
||||
:param int length: The length of password that you expect to set
|
||||
(If it's smaller than 3, it's same as 3.)
|
||||
:return: a random password. The format is
|
||||
'<random upper letter>-<random number>-<random special character>
|
||||
-<random ascii letters or digit characters or special symbols>'
|
||||
|
@@ -66,10 +66,19 @@ class TestDataUtils(base.TestCase):
|
||||
def test_rand_password_with_len(self):
|
||||
actual = data_utils.rand_password(8)
|
||||
self.assertIsInstance(actual, str)
|
||||
self.assertEqual(len(actual), 8)
|
||||
self.assertRegexpMatches(actual, "[A-Za-z0-9~!@#$%^&*_=+]{8}")
|
||||
actual2 = data_utils.rand_password(8)
|
||||
self.assertNotEqual(actual, actual2)
|
||||
|
||||
def test_rand_password_with_len_2(self):
|
||||
actual = data_utils.rand_password(2)
|
||||
self.assertIsInstance(actual, str)
|
||||
self.assertEqual(len(actual), 3)
|
||||
self.assertRegexpMatches(actual, "[A-Za-z0-9~!@#$%^&*_=+]{3}")
|
||||
actual2 = data_utils.rand_password(2)
|
||||
self.assertNotEqual(actual, actual2)
|
||||
|
||||
def test_rand_url(self):
|
||||
actual = data_utils.rand_url()
|
||||
self.assertIsInstance(actual, str)
|
||||
|
Reference in New Issue
Block a user