def process_put_post_patch_request( self, url, service_name, operation_name, params, type_dict, structure_svc, enum_svc, show_unreleased_apis, spec): """ Handles http post/put/patch request. todo: handle query, formData and header parameters """ # Path path_param_list, other_param_list, new_url = utils.extract_path_parameters( params, url) par_array = [] for field_info in path_param_list: parx = spec.convert_field_info_to_swagger_parameter( 'path', field_info, type_dict, structure_svc, enum_svc, show_unreleased_apis) par_array.append(parx) # Body body_param_list, other_param_list = utils.extract_body_parameters( other_param_list) if body_param_list: parx = spec.wrap_body_params( service_name, operation_name, body_param_list, type_dict, structure_svc, enum_svc, show_unreleased_apis) if parx is not None: par_array.append(parx) # Query query_param_list, other_param_list = utils.extract_query_parameters( other_param_list) for query_param in query_param_list: parx = spec.convert_field_info_to_swagger_parameter( 'query', query_param, type_dict, structure_svc, enum_svc, show_unreleased_apis) par_array.append(parx) # process query parameters for field_info in other_param_list: # See documentation of method flatten_query_param_spec to understand # handling of all the query parameters; filter as well as non # filter flattened_params = spec.flatten_query_param_spec( field_info, type_dict, structure_svc, enum_svc, show_unreleased_apis) if flattened_params is not None: par_array = par_array + flattened_params return par_array, new_url
def test_extract_body_parameters(self): # check for presence of body parameters inside params list # parameter 1 field_info_mock_1 = mock.Mock() element_map_mock_1 = mock.Mock() field_info_mock_1.metadata = {'Body' : element_map_mock_1} #parameter 2 field_info_mock_2 = mock.Mock() element_map_mock_2 = mock.Mock() field_info_mock_2.metadata = {'element_map_key' : element_map_mock_2} params = [field_info_mock_1, field_info_mock_2] body_params_actual, other_params_actual = utils.extract_body_parameters(params) body_params_expected = [field_info_mock_1] other_params_expected = [field_info_mock_2] self.assertEqual(body_params_expected, body_params_actual) self.assertEqual(other_params_expected, other_params_actual)