@@ -596,96 +596,93 @@ def __encode_multipart_formdata(fields: typing.Dict[str, typing.Any]) -> multipa
596596
597597 return m
598598
599- # comment out below for the time being after adding better inline model support
600- # ref: https://github.com/OpenAPITools/openapi-generator/pull/12104
601- #
602- #@patch.object(RESTClientObject, 'request')
603- #def test_inline_composition(self, mock_request):
604- # """Test case for inline_composition
605-
606- # testing composed schemas at inline locations # noqa: E501
607- # """
608- # single_char_str = 'a'
609- # json_bytes = self.__json_bytes(single_char_str)
610-
611- # # tx and rx json with composition at root level of schema for request + response body
612- # content_type = 'application/json'
613- # mock_request.return_value = self.__response(
614- # json_bytes
615- # )
616- # api_response = self.api.inline_composition(
617- # body=single_char_str,
618- # query_params={
619- # 'compositionAtRoot': single_char_str,
620- # 'compositionInProperty': {'someProp': single_char_str}
621- # },
622- # accept_content_types=(content_type,)
623- # )
624- # self.__assert_request_called_with(
625- # mock_request,
626- # 'http://petstore.swagger.io:80/v2/fake/inlineComposition/',
627- # accept_content_type=content_type,
628- # content_type=content_type,
629- # query_params=(('compositionAtRoot', 'a'), ('someProp', 'a')),
630- # body=json_bytes
631- # )
632- # self.assertEqual(api_response.body, single_char_str)
633- # self.assertTrue(isinstance(api_response.body, schemas.StrSchema))
634-
635- # # tx and rx json with composition at property level of schema for request + response body
636- # content_type = 'multipart/form-data'
637- # multipart_response = self.__encode_multipart_formdata(fields={'someProp': single_char_str})
638- # mock_request.return_value = self.__response(
639- # bytes(multipart_response),
640- # content_type=multipart_response.get_content_type()
641- # )
642- # api_response = self.api.inline_composition(
643- # body={'someProp': single_char_str},
644- # query_params={
645- # 'compositionAtRoot': single_char_str,
646- # 'compositionInProperty': {'someProp': single_char_str}
647- # },
648- # content_type=content_type,
649- # accept_content_types=(content_type,)
650- # )
651- # self.__assert_request_called_with(
652- # mock_request,
653- # 'http://petstore.swagger.io:80/v2/fake/inlineComposition/',
654- # accept_content_type=content_type,
655- # content_type=content_type,
656- # query_params=(('compositionAtRoot', 'a'), ('someProp', 'a')),
657- # fields=(
658- # api_client.RequestField(
659- # name='someProp',
660- # data=single_char_str,
661- # headers={'Content-Type': 'text/plain'}
662- # ),
663- # ),
664- # )
665- # self.assertEqual(api_response.body, {'someProp': single_char_str})
666- # self.assertTrue(isinstance(api_response.body.someProp, schemas.StrSchema))
667-
668- # # error thrown when a str is input which doesn't meet the composed schema length constraint
669- # invalid_value = ''
670- # variable_locations = 4
671- # for invalid_index in range(variable_locations):
672- # values = [single_char_str]*variable_locations
673- # values[invalid_index] = invalid_value
674- # with self.assertRaises(exceptions.ApiValueError):
675- # multipart_response = self.__encode_multipart_formdata(fields={'someProp': values[0]})
676- # mock_request.return_value = self.__response(
677- # bytes(multipart_response),
678- # content_type=multipart_response.get_content_type()
679- # )
680- # self.api.inline_composition(
681- # body={'someProp': values[1]},
682- # query_params={
683- # 'compositionAtRoot': values[2],
684- # 'compositionInProperty': {'someProp': values[3]}
685- # },
686- # content_type=content_type,
687- # accept_content_types=(content_type,)
688- # )
599+ @patch .object (RESTClientObject , 'request' )
600+ def test_inline_composition (self , mock_request ):
601+ """Test case for inline_composition
602+
603+ testing composed schemas at inline locations # noqa: E501
604+ """
605+ single_char_str = 'a'
606+ json_bytes = self .__json_bytes (single_char_str )
607+
608+ # tx and rx json with composition at root level of schema for request + response body
609+ content_type = 'application/json'
610+ mock_request .return_value = self .__response (
611+ json_bytes
612+ )
613+ api_response = self .api .inline_composition (
614+ body = single_char_str ,
615+ query_params = {
616+ 'compositionAtRoot' : single_char_str ,
617+ 'compositionInProperty' : {'someProp' : single_char_str }
618+ },
619+ accept_content_types = (content_type ,)
620+ )
621+ self .__assert_request_called_with (
622+ mock_request ,
623+ 'http://petstore.swagger.io:80/v2/fake/inlineComposition/' ,
624+ accept_content_type = content_type ,
625+ content_type = content_type ,
626+ query_params = (('compositionAtRoot' , 'a' ), ('someProp' , 'a' )),
627+ body = json_bytes
628+ )
629+ self .assertEqual (api_response .body , single_char_str )
630+ self .assertTrue (isinstance (api_response .body , schemas .StrSchema ))
631+
632+ # tx and rx json with composition at property level of schema for request + response body
633+ content_type = 'multipart/form-data'
634+ multipart_response = self .__encode_multipart_formdata (fields = {'someProp' : single_char_str })
635+ mock_request .return_value = self .__response (
636+ bytes (multipart_response ),
637+ content_type = multipart_response .get_content_type ()
638+ )
639+ api_response = self .api .inline_composition (
640+ body = {'someProp' : single_char_str },
641+ query_params = {
642+ 'compositionAtRoot' : single_char_str ,
643+ 'compositionInProperty' : {'someProp' : single_char_str }
644+ },
645+ content_type = content_type ,
646+ accept_content_types = (content_type ,)
647+ )
648+ self .__assert_request_called_with (
649+ mock_request ,
650+ 'http://petstore.swagger.io:80/v2/fake/inlineComposition/' ,
651+ accept_content_type = content_type ,
652+ content_type = content_type ,
653+ query_params = (('compositionAtRoot' , 'a' ), ('someProp' , 'a' )),
654+ fields = (
655+ api_client .RequestField (
656+ name = 'someProp' ,
657+ data = single_char_str ,
658+ headers = {'Content-Type' : 'text/plain' }
659+ ),
660+ ),
661+ )
662+ self .assertEqual (api_response .body , {'someProp' : single_char_str })
663+ self .assertTrue (isinstance (api_response .body .someProp , schemas .StrSchema ))
664+
665+ # error thrown when a str is input which doesn't meet the composed schema length constraint
666+ invalid_value = ''
667+ variable_locations = 4
668+ for invalid_index in range (variable_locations ):
669+ values = [single_char_str ]* variable_locations
670+ values [invalid_index ] = invalid_value
671+ with self .assertRaises (exceptions .ApiValueError ):
672+ multipart_response = self .__encode_multipart_formdata (fields = {'someProp' : values [0 ]})
673+ mock_request .return_value = self .__response (
674+ bytes (multipart_response ),
675+ content_type = multipart_response .get_content_type ()
676+ )
677+ self .api .inline_composition (
678+ body = {'someProp' : values [1 ]},
679+ query_params = {
680+ 'compositionAtRoot' : values [2 ],
681+ 'compositionInProperty' : {'someProp' : values [3 ]}
682+ },
683+ content_type = content_type ,
684+ accept_content_types = (content_type ,)
685+ )
689686
690687 def test_json_with_charset (self ):
691688 # serialization + deserialization of json with charset works
0 commit comments