|
| 1 | +"""Tests for IdentifierTransformer.to_path.""" |
| 2 | +from ingestify.domain.services.identifier_key_transformer import IdentifierTransformer |
| 3 | + |
| 4 | + |
| 5 | +def test_to_path_short_value_unchanged(): |
| 6 | + t = IdentifierTransformer() |
| 7 | + path = t.to_path("p", "d", {"key": "short"}) |
| 8 | + assert path == "key=short" |
| 9 | + |
| 10 | + |
| 11 | +def test_to_path_special_chars_url_encoded(): |
| 12 | + t = IdentifierTransformer() |
| 13 | + path = t.to_path("p", "d", {"key": "$99 mattress"}) |
| 14 | + assert path == "key=%2499%20mattress" |
| 15 | + |
| 16 | + |
| 17 | +def test_to_path_long_value_truncated_with_hash(): |
| 18 | + t = IdentifierTransformer() |
| 19 | + long_value = "a" * 50 |
| 20 | + path = t.to_path("p", "d", {"key": long_value}) |
| 21 | + # Truncated at 40 chars + _ + 8-char hash |
| 22 | + assert path.startswith("key=" + "a" * 40 + "_") |
| 23 | + assert len(path.split("=")[1]) == 40 + 1 + 8 # value_hash |
| 24 | + |
| 25 | + |
| 26 | +def test_to_path_long_value_hash_is_stable(): |
| 27 | + t = IdentifierTransformer() |
| 28 | + long_value = "keyword " * 10 |
| 29 | + path1 = t.to_path("p", "d", {"key": long_value}) |
| 30 | + path2 = t.to_path("p", "d", {"key": long_value}) |
| 31 | + assert path1 == path2 |
| 32 | + |
| 33 | + |
| 34 | +def test_to_path_integer_value_unchanged(): |
| 35 | + t = IdentifierTransformer() |
| 36 | + path = t.to_path("p", "d", {"id": 12345}) |
| 37 | + assert path == "id=12345" |
0 commit comments