diff options
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py new file mode 100644 index 0000000..7549faa --- /dev/null +++ b/tests/test_utils.py @@ -0,0 +1,40 @@ +from jwt.utils import ( + force_bytes, force_unicode, from_base64url_uint, to_base64url_uint +) + +import pytest + + +@pytest.mark.parametrize("inputval,expected", [ + (0, b'AA'), + (1, b'AQ'), + (255, b'_w'), + (65537, b'AQAB'), + (123456789, b'B1vNFQ'), + pytest.mark.xfail((-1, ''), raises=ValueError) +]) +def test_to_base64url_uint(inputval, expected): + actual = to_base64url_uint(inputval) + assert actual == expected + + +@pytest.mark.parametrize("inputval,expected", [ + (b'AA', 0), + (b'AQ', 1), + (b'_w', 255), + (b'AQAB', 65537), + (b'B1vNFQ', 123456789, ), +]) +def test_from_base64url_uint(inputval, expected): + actual = from_base64url_uint(inputval) + assert actual == expected + + +def test_force_unicode_raises_error_on_invalid_object(): + with pytest.raises(TypeError): + force_unicode({}) + + +def test_force_bytes_raises_error_on_invalid_object(): + with pytest.raises(TypeError): + force_bytes({}) |