11"""Unit tests for functions defined in utils.suid module."""
22
3+ from typing import Any
4+
5+ import pytest
6+
37from utils import suid
48
59
@@ -12,16 +16,62 @@ def test_get_suid(self) -> None:
1216 assert suid .check_suid (suid_value ), "Generated SUID is not valid"
1317 assert isinstance (suid_value , str ), "SUID should be a string"
1418
15- def test_check_suid_valid (self ) -> None :
19+ def test_check_suid_valid_uuid (self ) -> None :
1620 """Test that check_suid returns True for a valid UUID."""
1721 valid_suid = "123e4567-e89b-12d3-a456-426614174000"
22+ assert suid .check_suid (valid_suid ), "check_suid should return True for UUID"
23+
24+ def test_check_suid_valid_48char_hex (self ) -> None :
25+ """Test that check_suid returns True for a 48-char hex string."""
26+ valid_hex = "e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3c"
27+ assert len (valid_hex ) == 48
1828 assert suid .check_suid (
19- valid_suid
20- ), "check_suid should return True for a valid SUID"
29+ valid_hex
30+ ), "check_suid should return True for 48-char hex"
31+
32+ def test_check_suid_valid_conv_prefix (self ) -> None :
33+ """Test that check_suid returns True for conv_ + 48-char hex string."""
34+ valid_conv = "conv_e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3c"
35+ assert len (valid_conv ) == 53
36+ assert suid .check_suid (
37+ valid_conv
38+ ), "check_suid should return True for conv_ prefixed hex"
39+
40+ def test_check_suid_invalid_string (self ) -> None :
41+ """Test that check_suid returns False for an invalid string."""
42+ assert not suid .check_suid ("invalid-uuid" )
2143
22- def test_check_suid_invalid (self ) -> None :
23- """Test that check_suid returns False for an invalid UUID."""
24- invalid_suid = "invalid-uuid"
44+ def test_check_suid_valid_32char_hex_uuid (self ) -> None :
45+ """Test that check_suid returns True for 32-char hex (valid UUID format)."""
46+ # 32-char hex is a valid UUID format (without hyphens)
47+ assert suid .check_suid ("e6afd7aaa97b49ce8f4f96a801b07893" )
48+
49+ def test_check_suid_invalid_hex_wrong_length (self ) -> None :
50+ """Test that check_suid returns False for hex string with wrong length."""
51+ # 47 chars (not 48, not valid UUID)
52+ assert not suid .check_suid ("e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3" )
53+ # 49 chars (not 48, not valid UUID)
54+ assert not suid .check_suid ("e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3c1" )
55+
56+ def test_check_suid_invalid_conv_prefix_wrong_length (self ) -> None :
57+ """Test that check_suid returns False for conv_ with wrong hex length."""
58+ # conv_ + 47 chars (not 48)
59+ assert not suid .check_suid (
60+ "conv_e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3"
61+ )
62+ # conv_ + 49 chars (not 48)
2563 assert not suid .check_suid (
26- invalid_suid
27- ), "check_suid should return False for an invalid SUID"
64+ "conv_e6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53e3c1"
65+ )
66+
67+ def test_check_suid_invalid_non_hex_chars (self ) -> None :
68+ """Test that check_suid returns False for strings with non-hex characters."""
69+ # 48 chars but contains 'g' and 'z'
70+ invalid_hex = "g6afd7aaa97b49ce8f4f96a801b07893d9cb784d72e53ezz"
71+ assert len (invalid_hex ) == 48
72+ assert not suid .check_suid (invalid_hex )
73+
74+ @pytest .mark .parametrize ("invalid_type" , [None , 123 , [], {}])
75+ def test_check_suid_invalid_type (self , invalid_type : Any ) -> None :
76+ """Test that check_suid returns False for non-string types."""
77+ assert not suid .check_suid (invalid_type )
0 commit comments