Skip to content

Commit 077a95f

Browse files
committed
Add tests for lib
1 parent deb1130 commit 077a95f

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/test_lib.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import unittest
2+
from password_validator import lib
3+
4+
class TestLib(unittest.TestCase):
5+
def test_minimum(self):
6+
self.assertEqual(lib.minimum('TestPass', True, 8), True, 'should return True if pwd length is 8')
7+
self.assertEqual(lib.minimum('TestPasss', True, 8), True, 'should return True if pwd length is > 8')
8+
self.assertEqual(lib.minimum('TestPas', True, 8), False, 'should return False if pwd length is < 8')
9+
10+
def test_maximum(self):
11+
self.assertEqual(lib.maximum('TestPass', True, 8), True, 'should return True if pwd length is > 8')
12+
self.assertEqual(lib.maximum('TestPasss', True, 8), False, 'should return False if pwd length is > 8')
13+
self.assertEqual(lib.maximum('TestPas', True, 8), True, 'should return True if pwd length is > 8')
14+
15+
def test_letters(self):
16+
self.assertEqual(lib.letters('qwerTy', True), True, 'should return True if pwd has letters')
17+
self.assertEqual(lib.letters('qwe123', True), True, 'should return True if pwd has letters and digits')
18+
self.assertEqual(lib.letters('12344', True), False, 'should return False if pwd doesn\'t have letters')
19+
20+
self.assertEqual(lib.letters('qwerTy', False), False, 'should return False if pwd has letters and check is negative')
21+
self.assertEqual(lib.letters('qwe123', False), False, 'should return False if pwd has letters and digits, and check is negative')
22+
self.assertEqual(lib.letters('12344', False), True, 'should return True if pwd doesn\'t have letters and check is negative')
23+
24+
def test_digits(self):
25+
self.assertEqual(lib.digits('12344', True), True, 'should return True if pwd has digits')
26+
self.assertEqual(lib.digits('qwe123', True), True, 'should return True if pwd has digits and letters')
27+
self.assertEqual(lib.digits('qwerTy', True), False, 'should return False if pwd doesn\'t have digits')
28+
29+
self.assertEqual(lib.digits('12344', False), False, 'should return False if pwd has digits and the check is negative')
30+
self.assertEqual(lib.digits('qwe123', False), False, 'should return False if pwd has digits and letters, and the check is negative')
31+
self.assertEqual(lib.digits('qwerTy', False), True, 'should return True if pwd doesn\'t have digits and the check is negative')
32+
33+
def test_symbols(self):
34+
self.assertEqual(lib.symbols('qwe$u', True), True, 'should return True if pwd has symbols')
35+
self.assertEqual(lib.symbols('qwe£u', True), True, 'should return True if pwd has non-USD currency symbols')
36+
self.assertEqual(lib.symbols('qweu', True), False, 'should return False if pwd doesn\'t have symbols')
37+
38+
self.assertEqual(lib.symbols('qwe$u', False), False, 'should return False if pwd has symbols and check is negative')
39+
self.assertEqual(lib.symbols('qwe£u', False), False, 'should return False if pwd has non-USD currency symbols and check is negative')
40+
self.assertEqual(lib.symbols('qweu', False), True, 'should return True if pwd doesn\'t have symbols and check is negative')
41+
42+
43+
def test_spaces(self):
44+
self.assertEqual(lib.spaces('word1 word2', True), True, 'should return True if pwd has spaces')
45+
self.assertEqual(lib.spaces('word', True), False, 'should return False if pwd has no space')
46+
47+
self.assertEqual(lib.spaces('word1 word2', False), False, 'should return False if pwd has spaces and check is negative')
48+
self.assertEqual(lib.spaces('word', False), True, 'should return True if pwd has no space and check is negative')
49+
50+
def test_uppercase(self):
51+
self.assertEqual(lib.uppercase('upperCase', True), True, 'should return True if pwd has uppercase letters')
52+
self.assertEqual(lib.uppercase('lowercase', True), False, 'should return False if pwd has no uppercase letters')
53+
54+
self.assertEqual(lib.uppercase('uppserCase', False), False, 'should return False if pwd has uppercase letters and check is negative')
55+
self.assertEqual(lib.uppercase('lowercase', False), True, 'should return True if pwd has no uppercase letters and check is negative')
56+
57+
def test_lowercase(self):
58+
self.assertEqual(lib.lowercase('lowerCase', True), True, 'should return True if pwd has lowercase letters')
59+
self.assertEqual(lib.lowercase('UPPERCASE', True), False, 'should return False if pwd has no lowercase letters')
60+
61+
self.assertEqual(lib.lowercase('lowerCase', False), False, 'should return False if pwd has lowercase letters and check is negative')
62+
self.assertEqual(lib.lowercase('UPPERCASE', False), True, 'should return True if pwd has no lowercase letters and check is negative')
63+
64+
def test_applyRegexp(self):
65+
self.assertEqual(lib.applyRegexp('somePassword123', True, r'^[a-zA-Z]+\d{3}'), True, 'should return True if pwd has matches regex')
66+
self.assertEqual(lib.applyRegexp('somePassword123', True, r'^[a-zA-Z]+\d{4}'), False, 'should return False if pwd doesn\'t match regex')
67+
68+
self.assertEqual(lib.applyRegexp('somePassword123', False, r'^[a-zA-Z]+\d{3}'), False, 'should return False if pwd has matches regex and check is negative')
69+
self.assertEqual(lib.applyRegexp('somePassword123', False, r'^[a-zA-Z]+\d{4}'), True, 'should return True if pwd doesn\'t match regex and check is negative')
70+
71+
if __name__ == '__main__':
72+
unittest.main()

0 commit comments

Comments
 (0)