Skip to content

Commit 4d8cb5e

Browse files
committed
test: catch invalid response status codes
the spec requires this to be a valid HTTP code, invalid integers should not be supported
1 parent 02e7b32 commit 4d8cb5e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tests/test_parser/test_openapi.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,14 @@ def test_add_body_happy(self, mocker):
383383
assert endpoint.form_body_class == form_body_class
384384
assert endpoint.multipart_body == multipart_body
385385

386-
def test__add_responses_status_code_error(self, mocker):
386+
@pytest.mark.parametrize("response_status_code", ["not_a_number", 499])
387+
def test__add_responses_status_code_error(self, response_status_code, mocker):
387388
from openapi_python_client.parser.openapi import Endpoint, Schemas
388389

389390
schemas = Schemas()
390391
response_1_data = mocker.MagicMock()
391392
data = {
392-
"not_a_number": response_1_data,
393+
response_status_code: response_1_data,
393394
}
394395
endpoint = self.make_endpoint()
395396
parse_error = ParseError(data=mocker.MagicMock())
@@ -400,7 +401,7 @@ def test__add_responses_status_code_error(self, mocker):
400401

401402
assert response.errors == [
402403
ParseError(
403-
detail=f"Invalid response status code not_a_number (not a number), response will be ommitted from generated client"
404+
detail=f"Invalid response status code {response_status_code} (not a valid HTTP status code), response will be ommitted from generated client"
404405
)
405406
]
406407
response_from_data.assert_not_called()

0 commit comments

Comments
 (0)