Skip to content

Commit

Permalink
Merge pull request #355 from yozachar/workshop
Browse files Browse the repository at this point in the history
patch: adds `encoding` tests and docs
  • Loading branch information
yozachar committed Apr 3, 2024
2 parents 55e40ac + 7efc223 commit a2b4fc0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/api/encoding.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# encoding

::: validators.encoding.base58
::: validators.encoding.base64
6 changes: 6 additions & 0 deletions docs/api/encoding.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
encoding
--------

.. module:: validators.encoding
.. autofunction:: base58
.. autofunction:: base64
2 changes: 0 additions & 2 deletions docs/api/hashes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# hashes

::: validators.hashes.base58
::: validators.hashes.base64
::: validators.hashes.md5
::: validators.hashes.sha1
::: validators.hashes.sha224
Expand Down
2 changes: 0 additions & 2 deletions docs/api/hashes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ hashes
------

.. module:: validators.hashes
.. autofunction:: base58
.. autofunction:: base64
.. autofunction:: md5
.. autofunction:: sha1
.. autofunction:: sha224
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ nav:
- api/cron.md
- api/domain.md
- api/email.md
- api/encoding.md
- api/hashes.md
- api/hostname.md
- api/i18n.md
Expand Down
53 changes: 53 additions & 0 deletions tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Test Encodings."""

# external
import pytest

# local
from validators import ValidationError, base58, base64

# ==> base58 <== #


@pytest.mark.parametrize(
"value",
[
"cUSECaVvAiV3srWbFRvVPzm5YzcXJwPSwZfE7veYPHoXmR9h6YMQ",
"18KToMF5ckjXBYt2HAj77qsG3GPeej3PZn",
"n4FFXRNNEW1aA2WPscSuzHTCjzjs4TVE2Z",
"38XzQ9dPGb1uqbZsjPtUajp7omy8aefjqj",
],
)
def test_returns_true_on_valid_base58(value: str):
"""Test returns true on valid base58."""
assert base58(value)


@pytest.mark.parametrize(
"value",
["ThisIsAReallyLongStringThatIsDefinitelyNotBase58Encoded", "abcABC!@#", "InvalidBase58!"],
)
def test_returns_failed_validation_on_invalid_base58(value: str):
"""Test returns failed validation on invalid base58."""
assert isinstance(base58(value), ValidationError)


# ==> base64 <== #


@pytest.mark.parametrize(
"value",
["SGVsbG8gV29ybGQ=", "U29tZSBkYXRhIHN0cmluZw==", "YW55IGNhcm5hbCBwbGVhcw=="],
)
def test_returns_true_on_valid_base64(value: str):
"""Test returns true on valid base64."""
assert base64(value)


@pytest.mark.parametrize(
"value",
["SGVsbG8gV29ybGQ", "U29tZSBkYXRhIHN0cmluZw", "YW55IGNhcm5hbCBwbGVhc"],
)
def test_returns_failed_validation_on_invalid_base64(value: str):
"""Test returns failed validation on invalid base64."""
assert isinstance(base64(value), ValidationError)

0 comments on commit a2b4fc0

Please sign in to comment.