|
15 | 15 | from litestar._openapi.responses import ( |
16 | 16 | ResponseFactory, |
17 | 17 | create_error_responses, |
| 18 | + pascal_case_to_text, |
18 | 19 | ) |
19 | 20 | from litestar._openapi.schema_generation.plugins import openapi_schema_plugins |
20 | 21 | from litestar.datastructures import Cookie, ResponseHeader |
@@ -151,6 +152,37 @@ class AlternativePetException(HTTPException): |
151 | 152 | assert schema.type |
152 | 153 |
|
153 | 154 |
|
| 155 | +@pytest.mark.parametrize( |
| 156 | + ("string", "expected"), |
| 157 | + [ |
| 158 | + ("PetException", "Pet Exception"), |
| 159 | + ("InvalidAPIKeyError", "Invalid API Key Error"), |
| 160 | + ("HTTPException", "HTTP Exception"), |
| 161 | + ("ValidationException", "Validation Exception"), |
| 162 | + ("API", "API"), |
| 163 | + ("Error", "Error"), |
| 164 | + ("error", "error"), |
| 165 | + ("HTTP404Error", "HTTP404 Error"), |
| 166 | + ("Base64Decoder", "Base64 Decoder"), |
| 167 | + ("", ""), |
| 168 | + ], |
| 169 | +) |
| 170 | +def test_pascal_case_to_text(string: str, expected: str) -> None: |
| 171 | + assert pascal_case_to_text(string) == expected |
| 172 | + |
| 173 | + |
| 174 | +def test_create_error_responses_preserves_acronyms_in_description() -> None: |
| 175 | + class InvalidAPIKeyError(HTTPException): |
| 176 | + status_code = 401 |
| 177 | + |
| 178 | + _, response = next(create_error_responses(exceptions=[InvalidAPIKeyError])) |
| 179 | + |
| 180 | + assert response.content |
| 181 | + schema = response.content[MediaType.JSON].schema |
| 182 | + assert isinstance(schema, Schema) |
| 183 | + assert schema.description == "Invalid API Key Error" |
| 184 | + |
| 185 | + |
154 | 186 | def test_create_error_responses_with_non_http_status_code() -> None: |
155 | 187 | class HouseNotFoundError(HTTPException): |
156 | 188 | status_code: int = 420 |
|
0 commit comments