@@ -66,6 +66,32 @@ def test_from_dict_invalid_schema(self, mocker):
6666
6767
6868class TestEndpoint :
69+ def test_parse_yaml_body (self , mocker ):
70+ from openapi_python_client .parser .openapi import Endpoint , Schemas
71+ schema = mocker .MagicMock ()
72+ body = oai .RequestBody .construct (
73+ content = {"text/yaml" : oai .MediaType .construct (media_type_schema = schema )}
74+ )
75+ property_from_data = mocker .patch (f"{ MODULE_NAME } .property_from_data" )
76+ schemas = Schemas ()
77+
78+ result = Endpoint .parse_request_yaml_body (body = body , schemas = schemas , parent_name = "parent" )
79+
80+ property_from_data .assert_called_once_with (
81+ name = "yaml_body" , required = True , data = schema , schemas = schemas , parent_name = "parent"
82+ )
83+ assert result == property_from_data .return_value
84+
85+ def test_parse_yaml_body_no_data (self ):
86+ from openapi_python_client .parser .openapi import Endpoint , Schemas
87+
88+ body = oai .RequestBody .construct (content = {})
89+ schemas = Schemas ()
90+
91+ result = Endpoint .parse_request_yaml_body (body = body , schemas = schemas , parent_name = "parent" )
92+
93+ assert result == (None , schemas )
94+
6995 def test_parse_request_form_body (self , mocker ):
7096 ref = mocker .MagicMock ()
7197 body = oai .RequestBody .construct (
@@ -211,6 +237,12 @@ def test_add_body_happy(self, mocker):
211237 parse_request_json_body = mocker .patch .object (
212238 Endpoint , "parse_request_json_body" , return_value = (json_body , parsed_schemas )
213239 )
240+ yaml_body = mocker .MagicMock (autospec = Property )
241+ yaml_body_imports = mocker .MagicMock ()
242+ yaml_body .get_imports .return_value = {yaml_body_imports }
243+ parse_request_yaml_body = mocker .patch .object (
244+ Endpoint , "parse_request_yaml_body" , return_value = (yaml_body , parsed_schemas )
245+ )
214246 import_string_from_reference = mocker .patch (
215247 f"{ MODULE_NAME } .import_string_from_reference" , side_effect = ["import_1" , "import_2" ]
216248 )
@@ -233,15 +265,18 @@ def test_add_body_happy(self, mocker):
233265 assert response_schemas == parsed_schemas
234266 parse_request_form_body .assert_called_once_with (request_body )
235267 parse_request_json_body .assert_called_once_with (body = request_body , schemas = initial_schemas , parent_name = "name" )
268+ parse_request_yaml_body .assert_called_once_with (body = request_body , schemas = parsed_schemas , parent_name = "name" )
236269 parse_multipart_body .assert_called_once_with (request_body )
237270 import_string_from_reference .assert_has_calls (
238271 [
239272 mocker .call (form_body_reference , prefix = "...models" ),
240273 mocker .call (multipart_body_reference , prefix = "...models" ),
241274 ]
242275 )
276+ yaml_body .get_imports .assert_called_once_with (prefix = "..." )
243277 json_body .get_imports .assert_called_once_with (prefix = "..." )
244- assert endpoint .relative_imports == {"import_1" , "import_2" , "import_3" , json_body_imports }
278+ assert endpoint .relative_imports == {"import_1" , "import_2" , "import_3" , yaml_body_imports , json_body_imports }
279+ assert endpoint .yaml_body == yaml_body
245280 assert endpoint .json_body == json_body
246281 assert endpoint .form_body_reference == form_body_reference
247282 assert endpoint .multipart_body_reference == multipart_body_reference
@@ -312,12 +347,12 @@ def test__add_responses(self, mocker):
312347 response_1 = Response (
313348 status_code = 200 ,
314349 source = "source" ,
315- prop = DateTimeProperty (name = "datetime" , required = True , nullable = False , default = None ),
350+ prop = DateTimeProperty (name = "datetime" , required = True , nullable = False , default = None , description = None ),
316351 )
317352 response_2 = Response (
318353 status_code = 404 ,
319354 source = "source" ,
320- prop = DateProperty (name = "date" , required = True , nullable = False , default = None ),
355+ prop = DateProperty (name = "date" , required = True , nullable = False , default = None , description = None ),
321356 )
322357 response_from_data = mocker .patch (
323358 f"{ MODULE_NAME } .response_from_data" , side_effect = [(response_1 , schemas_1 ), (response_2 , schemas_2 )]
0 commit comments