Skip to content

Commit 2247d9b

Browse files
committed
feat: improve hashes and iban modules
- re-formats `hashes` and `iban.py`, fix typos - Uses type hints, adds relevant doc refs - Updates corresponding tests
1 parent 6ef1121 commit 2247d9b

File tree

12 files changed

+288
-248
lines changed

12 files changed

+288
-248
lines changed

docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@
1212

1313
::: validators.email
1414

15+
::: validators.hashes
16+
17+
::: validators.iban
18+
1519
::: validators.length

tests/test_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test Domain."""
22
# -*- coding: utf-8 -*-
33

4-
# standard
4+
# external
55
import pytest
66

77
# local

tests/test_email.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Test eMail."""
22
# -*- coding: utf-8 -*-
33

4-
# standard
4+
# external
55
import pytest
66

77
# local

tests/test_hashes.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
"""Test Hashes."""
2+
# -*- coding: utf-8 -*-
3+
4+
# external
5+
import pytest
6+
7+
# local
8+
from validators import md5, sha1, sha224, sha256, sha512, ValidationFailure
9+
10+
11+
# ==> md5 <== #
12+
13+
14+
@pytest.mark.parametrize(
15+
"value", ["d41d8cd98f00b204e9800998ecf8427e", "D41D8CD98F00B204E9800998ECF8427E"]
16+
)
17+
def test_returns_true_on_valid_md5(value: str):
18+
"""Test returns true on valid md5."""
19+
assert md5(value)
20+
21+
22+
@pytest.mark.parametrize(
23+
"value",
24+
[
25+
"z41d8cd98f00b204e9800998ecf8427e",
26+
"z8cd98f00b204e9800998ecf8427e",
27+
"z4aaaa1d8cd98f00b204e9800998ecf8427e",
28+
],
29+
)
30+
def test_returns_failed_validation_on_invalid_md5(value: str):
31+
"""Test returns failed validation on invalid md5."""
32+
assert isinstance(md5(value), ValidationFailure)
33+
34+
35+
# ==> sha1 <== #
36+
37+
38+
@pytest.mark.parametrize(
39+
"value",
40+
["da39a3ee5e6b4b0d3255bfef95601890afd80709", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709"],
41+
)
42+
def test_returns_true_on_valid_sha1(value: str):
43+
"""Test returns true on valid sha1."""
44+
assert sha1(value)
45+
46+
47+
@pytest.mark.parametrize(
48+
"value",
49+
[
50+
"za39a3ee5e6b4b0d3255bfef95601890afd80709",
51+
"da39e5e6b4b0d3255bfef95601890afd80709",
52+
"daaaa39a3ee5e6b4b0d3255bfef95601890afd80709",
53+
],
54+
)
55+
def test_returns_failed_validation_on_invalid_sha1(value: str):
56+
"""Test returns failed validation on invalid sha1."""
57+
assert isinstance(sha1(value), ValidationFailure)
58+
59+
60+
# ==> sha224 <== #
61+
62+
63+
@pytest.mark.parametrize(
64+
"value",
65+
[
66+
"d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",
67+
"D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F",
68+
],
69+
)
70+
def test_returns_true_on_valid_sha224(value: str):
71+
"""Test returns true on valid sha224."""
72+
assert sha224(value)
73+
74+
75+
@pytest.mark.parametrize(
76+
"value",
77+
[
78+
"z14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",
79+
"d028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",
80+
"daaa14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f",
81+
],
82+
)
83+
def test_returns_failed_validation_on_invalid_sha224(value: str):
84+
"""Test returns failed validation on invalid sha224."""
85+
assert isinstance(sha224(value), ValidationFailure)
86+
87+
88+
# ==> sha256 <== #
89+
90+
91+
@pytest.mark.parametrize(
92+
"value",
93+
[
94+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
95+
"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855",
96+
],
97+
)
98+
def test_returns_true_on_valid_sha256(value: str):
99+
"""Test returns true on valid sha256."""
100+
assert sha256(value)
101+
102+
103+
@pytest.mark.parametrize(
104+
"value",
105+
[
106+
"z3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
107+
"ec44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
108+
"eaaaa3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
109+
],
110+
)
111+
def test_returns_failed_validation_on_invalid_sha256(value: str):
112+
"""Test returns failed validation on invalid sha256."""
113+
assert isinstance(sha256(value), ValidationFailure)
114+
115+
116+
# ==> sha256 <== #
117+
118+
119+
@pytest.mark.parametrize(
120+
"value",
121+
[
122+
(
123+
"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d"
124+
"13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
125+
),
126+
(
127+
"CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D"
128+
"13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
129+
),
130+
],
131+
)
132+
def test_returns_true_on_valid_sha512(value: str):
133+
"""Test returns true on valid sha512."""
134+
assert sha512(value)
135+
136+
137+
@pytest.mark.parametrize(
138+
"value",
139+
[
140+
(
141+
"zf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d"
142+
"13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
143+
),
144+
(
145+
"cf8357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c"
146+
"5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
147+
),
148+
(
149+
"cf8aaaa3e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce4"
150+
"7d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
151+
),
152+
],
153+
)
154+
def test_returns_failed_validation_on_invalid_sha512(value: str):
155+
"""Test returns failed validation on invalid sha512."""
156+
assert isinstance(sha512(value), ValidationFailure)

tests/test_iban.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1+
"""Test IBAN."""
12
# -*- coding: utf-8 -*-
3+
4+
# external
25
import pytest
36

4-
import validators
7+
# local
8+
from validators import iban, ValidationFailure
59

610

7-
@pytest.mark.parametrize('value', [
8-
'GB82WEST12345698765432',
9-
'NO9386011117947'
10-
])
11-
def test_returns_true_on_valid_iban(value):
12-
assert validators.iban(value)
11+
@pytest.mark.parametrize("value", ["GB82WEST12345698765432", "NO9386011117947"])
12+
def test_returns_true_on_valid_iban(value: str):
13+
"""Test returns true on valid iban."""
14+
assert iban(value)
1315

1416

15-
@pytest.mark.parametrize('value', [
16-
'GB81WEST12345698765432',
17-
'NO9186011117947'
18-
])
19-
def test_returns_failed_validation_on_invalid_iban(value):
20-
result = validators.iban(value)
21-
assert isinstance(result, validators.ValidationFailure)
17+
@pytest.mark.parametrize("value", ["GB81WEST12345698765432", "NO9186011117947"])
18+
def test_returns_failed_validation_on_invalid_iban(value: str):
19+
"""Test returns failed validation on invalid iban."""
20+
assert isinstance(iban(value), ValidationFailure)

tests/test_md5.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_sha1.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_sha224.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_sha256.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

tests/test_sha512.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)