diff --git a/docs/api/encoding.md b/docs/api/encoding.md new file mode 100644 index 00000000..8f2794cb --- /dev/null +++ b/docs/api/encoding.md @@ -0,0 +1,4 @@ +# encoding + +::: validators.encoding.base58 +::: validators.encoding.base64 diff --git a/docs/api/encoding.rst b/docs/api/encoding.rst new file mode 100644 index 00000000..55d1799a --- /dev/null +++ b/docs/api/encoding.rst @@ -0,0 +1,6 @@ +encoding +-------- + +.. module:: validators.encoding +.. autofunction:: base58 +.. autofunction:: base64 diff --git a/docs/api/hashes.md b/docs/api/hashes.md index 0f583e1b..82b11bf0 100644 --- a/docs/api/hashes.md +++ b/docs/api/hashes.md @@ -1,7 +1,5 @@ # hashes -::: validators.hashes.base58 -::: validators.hashes.base64 ::: validators.hashes.md5 ::: validators.hashes.sha1 ::: validators.hashes.sha224 diff --git a/docs/api/hashes.rst b/docs/api/hashes.rst index 829f0992..bc77b7b2 100644 --- a/docs/api/hashes.rst +++ b/docs/api/hashes.rst @@ -2,8 +2,6 @@ hashes ------ .. module:: validators.hashes -.. autofunction:: base58 -.. autofunction:: base64 .. autofunction:: md5 .. autofunction:: sha1 .. autofunction:: sha224 diff --git a/mkdocs.yaml b/mkdocs.yaml index 895e5af0..511b66f0 100644 --- a/mkdocs.yaml +++ b/mkdocs.yaml @@ -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 diff --git a/tests/test_encoding.py b/tests/test_encoding.py new file mode 100644 index 00000000..86567ffb --- /dev/null +++ b/tests/test_encoding.py @@ -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)