Skip to content

Commit a2b4fc0

Browse files
authored
Merge pull request #355 from yozachar/workshop
patch: adds `encoding` tests and docs
2 parents 55e40ac + 7efc223 commit a2b4fc0

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

docs/api/encoding.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# encoding
2+
3+
::: validators.encoding.base58
4+
::: validators.encoding.base64

docs/api/encoding.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
encoding
2+
--------
3+
4+
.. module:: validators.encoding
5+
.. autofunction:: base58
6+
.. autofunction:: base64

docs/api/hashes.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# hashes
22

3-
::: validators.hashes.base58
4-
::: validators.hashes.base64
53
::: validators.hashes.md5
64
::: validators.hashes.sha1
75
::: validators.hashes.sha224

docs/api/hashes.rst

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ hashes
22
------
33

44
.. module:: validators.hashes
5-
.. autofunction:: base58
6-
.. autofunction:: base64
75
.. autofunction:: md5
86
.. autofunction:: sha1
97
.. autofunction:: sha224

mkdocs.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ nav:
7676
- api/cron.md
7777
- api/domain.md
7878
- api/email.md
79+
- api/encoding.md
7980
- api/hashes.md
8081
- api/hostname.md
8182
- api/i18n.md

tests/test_encoding.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Test Encodings."""
2+
3+
# external
4+
import pytest
5+
6+
# local
7+
from validators import ValidationError, base58, base64
8+
9+
# ==> base58 <== #
10+
11+
12+
@pytest.mark.parametrize(
13+
"value",
14+
[
15+
"cUSECaVvAiV3srWbFRvVPzm5YzcXJwPSwZfE7veYPHoXmR9h6YMQ",
16+
"18KToMF5ckjXBYt2HAj77qsG3GPeej3PZn",
17+
"n4FFXRNNEW1aA2WPscSuzHTCjzjs4TVE2Z",
18+
"38XzQ9dPGb1uqbZsjPtUajp7omy8aefjqj",
19+
],
20+
)
21+
def test_returns_true_on_valid_base58(value: str):
22+
"""Test returns true on valid base58."""
23+
assert base58(value)
24+
25+
26+
@pytest.mark.parametrize(
27+
"value",
28+
["ThisIsAReallyLongStringThatIsDefinitelyNotBase58Encoded", "abcABC!@#", "InvalidBase58!"],
29+
)
30+
def test_returns_failed_validation_on_invalid_base58(value: str):
31+
"""Test returns failed validation on invalid base58."""
32+
assert isinstance(base58(value), ValidationError)
33+
34+
35+
# ==> base64 <== #
36+
37+
38+
@pytest.mark.parametrize(
39+
"value",
40+
["SGVsbG8gV29ybGQ=", "U29tZSBkYXRhIHN0cmluZw==", "YW55IGNhcm5hbCBwbGVhcw=="],
41+
)
42+
def test_returns_true_on_valid_base64(value: str):
43+
"""Test returns true on valid base64."""
44+
assert base64(value)
45+
46+
47+
@pytest.mark.parametrize(
48+
"value",
49+
["SGVsbG8gV29ybGQ", "U29tZSBkYXRhIHN0cmluZw", "YW55IGNhcm5hbCBwbGVhc"],
50+
)
51+
def test_returns_failed_validation_on_invalid_base64(value: str):
52+
"""Test returns failed validation on invalid base64."""
53+
assert isinstance(base64(value), ValidationError)

0 commit comments

Comments
 (0)