Skip to content

Commit

Permalink
Refactor generate_password, fix test names
Browse files Browse the repository at this point in the history
  • Loading branch information
davoclavo committed Mar 31, 2015
1 parent aad416b commit 5aa0500
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions passplz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
def generate_password(password_length=16):
"""Generate a random password of length ``password_length``."""
random_string = ""
while len(random_string) < password_length + 4*(password_length/16.0):
random_string += str(uuid4())
random_password = random_string.replace('-', '')[:password_length]
while len(random_string) < password_length:
random_string += uuid4().hex
random_password = random_string[:password_length]
return random_password
8 changes: 4 additions & 4 deletions passplz/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import passplz


class TestPasswordy(TestCase):
class TestPassword(TestCase):
"""Generate a password and make sure it has length 16."""
def test_is_string(self):
def test_default_length(self):
"""
Test if the generate_password function of passplz is callable and
if the returned password has length 16.
"""
password = passplz.generate_password()
self.assertEqual(16, len(password))

def test_lengths(self):
def test_various_lengths(self):
"""
Test if generation of 35 character long passwords work.
Test if generation of various character long passwords work.
"""
for i in range(2, 160):
password = passplz.generate_password(i)
Expand Down

0 comments on commit 5aa0500

Please sign in to comment.