-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_test.py
39 lines (30 loc) · 1.25 KB
/
generate_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import secrets
import unittest
import generate
from generate import MAX_LENGTH, MIN_LENGTH
class TestMain(unittest.TestCase):
def test_invalid_input(self):
output = generate.main(["asdf"])
self.assertEqual(1, len(output["items"]))
self.assertFalse(output["items"][0]["valid"])
def test_default_length(self):
output = generate.main([])
self.assertEqual(16, len(output["items"][0]["title"]))
self.assertEqual(16, len(output["items"][0]["arg"]))
class TestGenerate(unittest.TestCase):
def test_length(self):
password = generate.generate(20)
self.assertEqual(20, len(password))
def test_generate_complexity(self):
for i in range(0, 10):
password = generate.generate(20)
self.assertRegex(password, ".*[0-9]+.*")
self.assertRegex(password, r".*[!@#$%^&*()\-_=+\"',./\\:;{}~|]+.*")
def test_no_dupes(self):
passwords = []
for i in range(0, 10000):
length = secrets.randbelow(MAX_LENGTH - MIN_LENGTH) + MIN_LENGTH + 1
password = generate.generate(length)
passwords.append(password)
self.assertEqual(length, len(password))
self.assertEqual(len(passwords), len(set(passwords)))