def test_root_values_are_added_to_query(parse_rest_request, send): rest = RESTMagic() rest.root = RESTRequest(method='POST', url='http://example.org') parse_rest_request.return_value = RESTRequest(url='test') rest.rest('GET test') args = send.call_args[0] assert args[0] == RESTRequest(method='POST', url='http://example.org/test')
def test_extract_option_handled(send, display_dict, display_response, response_parser, option): RESTMagic().rest(line=f"{option} test GET http://localhost") response_parser.assert_called_once_with(response='test sended', expression='test', content_subtype=None) display_dict.assert_called_once()
def test_variables_expansion_used_by_rest_command(mocker, expand_variables): mocker.patch('restmagic.magic.RESTMagic.get_user_namespace', return_value={'ct': 'application/json'}) RESTMagic().rest(line='GET http://localhost', cell='Content-Type: $ct') # line variables are already expanded by IPython, # expand_variables() should be called only for cell text expand_variables.assert_called_once_with('Content-Type: $ct', {'ct': 'application/json'})
def test_default_method_and_scheme_added_to_query(parse_rest_request, send): rest = RESTMagic() parse_rest_request.return_value = RESTRequest(url='test') rest.rest('test') args = send.call_args[0] assert args[0] == RESTRequest(method='GET', url='https://test')
def test_send_response_returned_by_rest_command(send): result = RESTMagic().rest('GET http://localhost') send.assert_called_once() assert result == 'test sended'
def test_parser_option_handled(send, display_dict, display_response, response_parser, parser): RESTMagic().rest(line=f"--parser {parser} -e test GET http://localhost") response_parser.assert_called_once_with(response=mock.ANY, expression=mock.ANY, content_subtype=parser)
def test_timeout_option_handled(send): RESTMagic().rest(line='GET http://localhost') assert send.call_args[1]['timeout'] == 10 RESTMagic().rest(line='--timeout 1.01 GET http://localhost') assert send.call_args[1]['timeout'] == 1.01
def test_proxy_option_handled(send): RESTMagic().rest(line='--proxy 127.0.0.1:9000 GET http://localhost') assert send.call_args[1]['proxy'] == '127.0.0.1:9000'
def test_max_redirects_option_handled(send): RESTMagic().rest(line='GET http://localhost') assert send.call_args[1]['max_redirects'] == 30 RESTMagic().rest(line='--max-redirects 0 GET http://localhost') assert send.call_args[1]['max_redirects'] == 0
def test_args_combined(root_args, args, expected): rest = RESTMagic() rest.root_args = root_args assert rest.get_args(args).verbose == expected
def test_insecure_option_handled(send): RESTMagic().rest(line='-k GET http://localhost') assert send.call_args[1]['verify'] is False
def test_usage_displayed_on_parse_error(parse_rest_request, display_usage_example): parse_rest_request.side_effect = ParseError('test') result = RESTMagic().rest('') assert result is None display_usage_example.assert_called_once()
def test_no_display_in_quiet_mode(display_response): RESTMagic().rest(line='-q GET http://localhost') display_response.assert_not_called()
def test_session_dumped_in_verbose_mode(dump): RESTMagic().rest(line='-v GET http://localhost') dump.assert_called_once()
def test_command_options_extracted_from_query(parse_rest_request): RESTMagic().rest(line='-v -v -v GET http://localhost') parse_rest_request.assert_called_once_with('GET http://localhost\n')
def test_trailing_newline_is_removed_from_cell(ip, parse_rest_request): RESTMagic().rest(line="POST http://localhost", cell="\n1234\n\n") parse_rest_request.assert_called_once_with('POST http://localhost\n\n1234')