-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_password_meter.py
106 lines (80 loc) · 3.01 KB
/
test_password_meter.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pytest
from password_meter import Password
from constants import ALL, USE_LETTERS, USE_DIGITS, USE_PUNCTATIONS
# set up fixture
@pytest.fixture(scope='module')
def password():
pswd = Password(':abcdX01J!b#')
yield pswd
def test_attributes(password):
assert isinstance(password, Password)
assert isinstance(password.password, str)
assert password.len == 12
assert password.nupper == 2
assert password.nlower == 5
assert password.ndigit == 2
assert password.symbol == 3
assert password.requirement == 5
def test_middle_ns(password):
assert password._middle_ns() / 2 == 3
def test_only_letters(password):
assert password._only_letters() == 0
def test_only_digits(password):
assert password._only_digits() == 0
def test_consecutive_letter(password):
assert password._consecutive_letter() / -2 == 3
def test_consecutive_digit(password):
assert password._consecutive_digit() / -2 == 1
def test_check_sequential(password):
assert password._check_sequential() / -3 == 2
def test_global_score(password):
password._global_score()
assert password.score >= 100.0
# test specifications types
def test_random_password_spec(password):
assert ALL == USE_LETTERS + USE_DIGITS + USE_PUNCTATIONS
# new find safe password test with cases:
passwd, score = Password().find(8, spec=USE_DIGITS)
assert len(passwd) == 8
s_digits = sum(c.isdigit() for c in passwd)
assert s_digits == 8
passwd, score = Password().find(8, spec=USE_LETTERS)
s_letters = sum(c.isalpha() for c in passwd)
assert s_letters == 8
assert score > 5.0 and score < 100.0
# test special cases password
def test_specials_cases_password():
special_pass = Password('')
assert special_pass.len == 0
assert special_pass.nupper == 0
assert special_pass.nlower == 0
assert special_pass.ndigit == 0
assert special_pass.symbol == 0
assert special_pass.requirement == 0
# score compute part A and B
special_pass._compute_addition()
assert special_pass.score == 0
special_pass._compute_deduction()
assert special_pass.score == 0
special_pass._global_score()
assert special_pass.score == 0
# only digits
special_pass = Password('0123456789')
assert special_pass._only_digits() == -10.0
assert special_pass._consecutive_digit() == -18.0
assert special_pass._check_sequential() == -24.0
# only letters
special_pass = Password('ABCDefcbAARk')
assert special_pass._only_letters() == - 12.0
assert special_pass._consecutive_letter() == -20.0
assert special_pass._check_sequential() == -6.0
def test_repetitive_chars2():
""" test complexe function _repetitive_chars2 """
passwd = Password('axbxcxdxexfx')
assert passwd._repetitive_chars2() == 0
passwd = Password('abbbbb01b')
assert passwd._repetitive_chars2() == -16
passwd = Password('000000013xbv11')
assert passwd._repetitive_chars2() == -37
passwd = Password('Oharrrrrrrrrrrrrrrrg!')
assert passwd._repetitive_chars2() == -100