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:
Masayuki Igawa
2015-06-05 00:35:13 +09:00
parent 3fe26726c0
commit e7cf550d53
2 changed files with 10 additions and 0 deletions

View File

@@ -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>'

View File

@@ -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)