@@ -48,7 +48,10 @@ class TestSwaggerClient(unittest.TestCase):
4848 "head_with_optional_param" ,
4949 "put_with_invalid_enum_param" ,
5050 "get_with_allOf_in_body_param" ,
51- "test_get_with_allOf_multiple_in_body_param"
51+ "get_with_allOf_multiple_in_body_param" ,
52+ "get_with_something_in_path" ,
53+ "get_with_header_parameter" ,
54+ "get_with_request_body_application_json"
5255 ]
5356
5457 @classmethod
@@ -91,8 +94,9 @@ def setUp(self):
9194
9295 def test_client_methods_exist (self ):
9396 for method_name in self .generated_method_names :
94- self .assertTrue (hasattr (self .client .__class__ , method_name ) and
95- callable (getattr (self .client .__class__ , method_name )))
97+ with self .subTest (method_name ):
98+ self .assertTrue (hasattr (self .client .__class__ , method_name ) and
99+ callable (getattr (self .client .__class__ , method_name )))
96100
97101 def test_get_with_path_query_params (self ):
98102 http_method = "get"
@@ -401,6 +405,56 @@ def test_put_with_invalid_enum_param(self):
401405 '--query-param' , query_param_invalid ])
402406 self .assertEqual (e .exception .code , 2 )
403407
408+ def test_get_with_something_in_path (self ):
409+ self ._test ("/with/something/.well-known/in/path" , "get" )
410+
411+ def test_get_with_header_parameter (self ):
412+ self ._test ("/with/header/parameter" ,
413+ "get" ,
414+ headers = {"some_header" : "foo" },
415+ command_args = ["--some-header" , "foo" ])
416+
417+ def test_get_with_request_body_application_json (self ):
418+ self ._test ("/with/request_body/not_application/json" ,
419+ "get" ,
420+ json = {"foo" : "bar" },
421+ command_args = ["--foo" , "bar" ])
422+
423+ def _test (self ,
424+ path : str ,
425+ http_method : str ,
426+ json : dict = None ,
427+ stream : bool = False ,
428+ params : dict = None ,
429+ headers : dict = None ,
430+ timeout = mock .ANY ,
431+ command_args : list = None ):
432+
433+ params = params or {}
434+ headers = headers or {}
435+ command_args = command_args or []
436+
437+ command = self .get_command (http_method , path )
438+ url = self .url_base + path
439+
440+ with mock .patch ('requests.Session.request' ) as mock_request , \
441+ mock .patch ('hca.util._ClientMethodFactory._consume_response' ) as mock_consume_response :
442+ mock_request .return_value = self .dummy_response
443+
444+ args = self .parser .parse_args ([command ] + command_args )
445+ args .entry_point (args )
446+ mock_consume_response .assert_called_once_with (mock .ANY )
447+ mock_request .assert_called_once_with (http_method ,
448+ url ,
449+ json = json ,
450+ stream = stream ,
451+ params = params ,
452+ headers = headers ,
453+ timeout = timeout )
454+
455+ def get_command (self , http_method , path ):
456+ return self .client ._build_method_name (http_method , path ).replace ('_' , '-' )
457+
404458
405459if __name__ == "__main__" :
406460 unittest .main ()
0 commit comments