def test__add_responses_status_code_error(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas schemas = Schemas() response_1_data = mocker.MagicMock() response_2_data = mocker.MagicMock() data = { "not_a_number": response_1_data, } endpoint = Endpoint( path="path", method="method", description=None, name="name", requires_security=False, tag="tag", relative_imports={"import_3"}, ) parse_error = ParseError(data=mocker.MagicMock()) response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas) assert response.errors == [ ParseError( detail= f"Invalid response status code not_a_number (not a number), response will be ommitted from generated client" ) ]
def test__add_responses_error(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas schemas = Schemas() response_1_data = mocker.MagicMock() response_2_data = mocker.MagicMock() data = { "200": response_1_data, "404": response_2_data, } endpoint = self.make_endpoint() parse_error = ParseError(data=mocker.MagicMock()) response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) config = MagicMock() response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas, config=config) response_from_data.assert_has_calls( [ mocker.call(status_code=200, data=response_1_data, schemas=schemas, parent_name="name", config=config), mocker.call(status_code=404, data=response_2_data, schemas=schemas, parent_name="name", config=config), ] ) assert response.errors == [ ParseError( detail=f"Cannot parse response for status code 200, response will be ommitted from generated client", data=parse_error.data, ), ParseError( detail=f"Cannot parse response for status code 404, response will be ommitted from generated client", data=parse_error.data, ), ]
def test__add_responses_status_code_error(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas schemas = Schemas() response_1_data = mocker.MagicMock() data = { "not_a_number": response_1_data, } endpoint = self.make_endpoint() parse_error = ParseError(data=mocker.MagicMock()) response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) config = MagicMock() response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas, config=config) assert response.errors == [ ParseError( detail= f"Invalid response status code not_a_number (not a number), response will be ommitted from generated client" ) ] response_from_data.assert_not_called()
def test__add_responses_error(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Schemas schemas = Schemas() response_1_data = mocker.MagicMock() response_2_data = mocker.MagicMock() data = { "200": response_1_data, "404": response_2_data, } endpoint = Endpoint( path="path", method="method", description=None, name="name", requires_security=False, tag="tag", relative_imports={"import_3"}, ) parse_error = ParseError(data=mocker.MagicMock()) response_from_data = mocker.patch(f"{MODULE_NAME}.response_from_data", return_value=(parse_error, schemas)) response, schemas = Endpoint._add_responses(endpoint=endpoint, data=data, schemas=schemas) response_from_data.assert_has_calls([ mocker.call(status_code=200, data=response_1_data, schemas=schemas, parent_name="name"), mocker.call(status_code=404, data=response_2_data, schemas=schemas, parent_name="name"), ]) assert response.errors == [ ParseError( detail= f"Cannot parse response for status code 200, response will be ommitted from generated client", data=parse_error.data, ), ParseError( detail= f"Cannot parse response for status code 404, response will be ommitted from generated client", data=parse_error.data, ), ]
def test__add_responses(self, mocker): from openapi_python_client.parser.openapi import Endpoint, Response from openapi_python_client.parser.properties import DateProperty, DateTimeProperty response_1_data = mocker.MagicMock() response_2_data = mocker.MagicMock() data = { "200": response_1_data, "404": response_2_data, } endpoint = self.make_endpoint() schemas = mocker.MagicMock() schemas_1 = mocker.MagicMock() schemas_2 = mocker.MagicMock() response_1 = Response( status_code=200, source="source", prop=DateTimeProperty(name="datetime", required=True, nullable=False, default=None), ) response_2 = Response( status_code=404, source="source", prop=DateProperty(name="date", required=True, nullable=False, default=None), ) response_from_data = mocker.patch( f"{MODULE_NAME}.response_from_data", side_effect=[(response_1, schemas_1), (response_2, schemas_2)] ) config = MagicMock() endpoint, response_schemas = Endpoint._add_responses( endpoint=endpoint, data=data, schemas=schemas, config=config ) response_from_data.assert_has_calls( [ mocker.call(status_code=200, data=response_1_data, schemas=schemas, parent_name="name", config=config), mocker.call( status_code=404, data=response_2_data, schemas=schemas_1, parent_name="name", config=config ), ] ) assert endpoint.responses == [response_1, response_2] assert endpoint.relative_imports == { "from dateutil.parser import isoparse", "from typing import cast", "import datetime", "import_3", } assert response_schemas == schemas_2