Skip to content

Commit 5e037a5

Browse files
committed
fix: align tests with updated openapi examples and registry specificity
1 parent 4bcb3a2 commit 5e037a5

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

tests/test_openapi.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,21 @@ def test_example_error_detail_structure(self) -> None:
114114
assert "msg" in error
115115
assert "type" in error
116116

117-
def test_example_error_type_is_missing(self) -> None:
118-
"""Generated examples should use 'missing' error type."""
117+
def test_example_error_type_is_valid(self) -> None:
118+
"""Generated examples should use known pydantic error types."""
119+
known_types = {
120+
"missing",
121+
"string_too_short",
122+
"string_pattern_mismatch",
123+
"too_small",
124+
"too_large",
125+
}
119126
examples = get_validation_error_examples(UserModel)
120127
for example in examples:
121128
for error in example["value"]["detail"]:
122-
assert error["type"] == "missing"
129+
assert error["type"] in known_types, (
130+
f"Unknown error type '{error['type']}' not in {known_types}"
131+
)
123132

124133
def test_example_loc_starts_with_body(self) -> None:
125134
"""Error location should start with 'body'."""

tests/test_registry.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,22 @@ def handler2(exc: Exception) -> HttpResponse:
9595
result = GlobalErrorHandlerRegistry.get_handler(ValueError("test"))
9696
assert result is handler2
9797

98-
def test_multiple_handlers_first_match_wins(self) -> None:
99-
"""Test that first matching handler (by registration order) wins."""
98+
def test_multiple_handlers_most_specific_wins(self) -> None:
99+
"""Test that the most specific matching handler wins."""
100100

101101
def base_handler(exc: Exception) -> HttpResponse:
102102
return HttpResponse("base")
103103

104104
def specific_handler(exc: Exception) -> HttpResponse:
105105
return HttpResponse("specific")
106106

107-
# Register base first
107+
# Register base first, then specific
108108
GlobalErrorHandlerRegistry.register(Exception, base_handler)
109109
GlobalErrorHandlerRegistry.register(ValueError, specific_handler)
110110

111-
# Exception handler matches first (registered first) for ValueError
111+
# ValueError handler is more specific, so it wins
112112
result = GlobalErrorHandlerRegistry.get_handler(ValueError("test"))
113-
assert result is base_handler
113+
assert result is specific_handler
114114

115115

116116
class TestPublicAPIFunctions:

0 commit comments

Comments
 (0)