From 87a5894df390c8e1968ba84dea249dd947b4af12 Mon Sep 17 00:00:00 2001 From: Callum Dempsey Leach Date: Wed, 21 Aug 2024 22:12:04 +0100 Subject: [PATCH 1/2] feat: Negative Tests --- tests/test_ksuid.py | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/test_ksuid.py b/tests/test_ksuid.py index 63d8a0b..0fa138b 100644 --- a/tests/test_ksuid.py +++ b/tests/test_ksuid.py @@ -1,6 +1,7 @@ import json import os import typing as t +import uuid from datetime import datetime, timedelta, timezone import pytest @@ -71,6 +72,52 @@ def test_to_from_base62(): # Assert assert ksuid == ksuid_from_base62 +def test_to_from_base62_invalid_base62_string(): + # Arrange + ksuid = Ksuid() + invalid_base62 = "invalid_base62_string!" + + # Act & Assert + with pytest.raises(ValueError): + ksuid.from_base62(invalid_base62) + +def test_to_from_base62_empty_string(): + # Arrange + ksuid = Ksuid() + empty_base62 = "" + + # Act & Assert + with pytest.raises(IndexError): # this looks wrong + ksuid.from_base62(empty_base62) + +def test_to_from_base62_mismatched_id(): + # Arrange + ksuid = Ksuid() + base62 = str("00000000000000000000000-00") + + # Act & Assert + with pytest.raises(ValueError): # this looks wrong + ksuid.from_base62(base62) + +def test_to_from_base62_digit_input(): + # Arrange + ksuid = Ksuid() + non_string_input = "1234567890" + + # Act & Assert + with pytest.raises(Exception): + ksuid.from_base62(non_string_input) + +def test_to_from_base62_zero_value_ksuid(): + # Arrange + zero_ksuid = Ksuid.from_base62("000000000000000000000000000") + base62 = str(zero_ksuid) + + # Act + ksuid_from_base62 = zero_ksuid.from_base62(base62) + + # Assert + assert zero_ksuid == ksuid_from_base62 def test_to_from_bytes(): # Arrange From 94c09a5c0c93c3eeaacba1154713221c761e5526 Mon Sep 17 00:00:00 2001 From: Callum Dempsey Leach Date: Wed, 21 Aug 2024 22:13:31 +0100 Subject: [PATCH 2/2] fix: remove unused import --- tests/test_ksuid.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_ksuid.py b/tests/test_ksuid.py index 0fa138b..fecd111 100644 --- a/tests/test_ksuid.py +++ b/tests/test_ksuid.py @@ -1,7 +1,6 @@ import json import os import typing as t -import uuid from datetime import datetime, timedelta, timezone import pytest