From 538a9642185ebb7e6d040f82185f1709118a4755 Mon Sep 17 00:00:00 2001 From: Adam Gray Date: Mon, 8 Jun 2020 12:51:42 +0100 Subject: [PATCH 1/2] allow no content responses --- openapi_python_client/openapi_parser/responses.py | 2 +- tests/test_openapi_parser/test_responses.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/openapi_python_client/openapi_parser/responses.py b/openapi_python_client/openapi_parser/responses.py index c00cca8ea..f9f373ea3 100644 --- a/openapi_python_client/openapi_parser/responses.py +++ b/openapi_python_client/openapi_parser/responses.py @@ -80,7 +80,7 @@ def constructor(self) -> str: def response_from_dict(*, status_code: int, data: Dict[str, Any]) -> Response: """ Generate a Response from the OpenAPI dictionary representation of it """ if "content" not in data: - raise ParseError(data) + return Response(status_code=status_code) content = data["content"] if "application/json" in content: diff --git a/tests/test_openapi_parser/test_responses.py b/tests/test_openapi_parser/test_responses.py index 41fc0452b..72eb6c3f3 100644 --- a/tests/test_openapi_parser/test_responses.py +++ b/tests/test_openapi_parser/test_responses.py @@ -95,11 +95,15 @@ def test_constructor(self): class TestResponseFromDict: - def test_response_from_dict_no_content(self): + def test_response_from_dict_no_content(self, mocker): from openapi_python_client.openapi_parser.responses import response_from_dict + Response = mocker.patch(f"{MODULE_NAME}.Response") - with pytest.raises(ValueError): - response_from_dict(status_code=200, data={}) + status_code = mocker.MagicMock(autospec=int) + response = response_from_dict(status_code=status_code, data={}) + + Response.assert_called_once_with(status_code=status_code) + assert response == Response() def test_response_from_dict_unsupported_content_type(self): from openapi_python_client.openapi_parser.responses import response_from_dict From f1641913a438be45693d3dc9ee81c22f57916724 Mon Sep 17 00:00:00 2001 From: Adam Gray Date: Mon, 8 Jun 2020 13:00:24 +0100 Subject: [PATCH 2/2] correct code formatting --- tests/test_openapi_parser/test_responses.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_openapi_parser/test_responses.py b/tests/test_openapi_parser/test_responses.py index 72eb6c3f3..0dc4f3e44 100644 --- a/tests/test_openapi_parser/test_responses.py +++ b/tests/test_openapi_parser/test_responses.py @@ -97,11 +97,12 @@ def test_constructor(self): class TestResponseFromDict: def test_response_from_dict_no_content(self, mocker): from openapi_python_client.openapi_parser.responses import response_from_dict + Response = mocker.patch(f"{MODULE_NAME}.Response") status_code = mocker.MagicMock(autospec=int) - response = response_from_dict(status_code=status_code, data={}) - + response = response_from_dict(status_code=status_code, data={}) + Response.assert_called_once_with(status_code=status_code) assert response == Response()