def test_body(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request) self.assertEqual(request, request.prepped.body) #pylint:disable=no-member
def test_body(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request) self.assertEqual(request, request.prepped.body)
def test_ssl_verification(self): client = HTTPClient('https://test/') client.session.cert = '/path/to/cert' client.session.verify = 'ca-cert' request = PreparedRequest(Request('go')) client._prepare_request(request) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request)
def test_success_200(): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) responses.add( responses.POST, 'http://test/', status=200, body='{"jsonrpc": "2.0", "result": 5, "id": 1}') client._send_message(request)
def test_success_200(): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) responses.add(responses.POST, 'http://test/', status=200, body='{"jsonrpc": "2.0", "result": 5, "id": 1}') client._send_message(request)
def test_invalid_request(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) # Impossible to pass an invalid dict, so just assume the exception was raised responses.add( responses.POST, 'http://test/', status=400, body=requests.exceptions.InvalidSchema()) with self.assertRaises(requests.exceptions.InvalidSchema): client._send_message(request)
def test_invalid_request(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) # Impossible to pass an invalid dict, so just assume the exception was raised responses.add(responses.POST, 'http://test/', status=400, body=requests.exceptions.InvalidSchema()) with self.assertRaises(requests.exceptions.InvalidSchema): client._send_message(request)
def test_custom_headers(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request, headers={'Content-Type': 'application/json-rpc'}) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request) #pylint:disable=no-member # Header set by argument self.assertEqual('application/json-rpc', request.prepped.headers['Content-Type']) # Header set by DEFAULT_HEADERS self.assertEqual('application/json', request.prepped.headers['Accept']) # Header set by Requests default_headers self.assertIn('Content-Length', request.prepped.headers)
def test_send_custom_headers(self): client = HTTPClient('http://test/') client.session.headers['Content-Type'] = 'application/json-rpc' request = PreparedRequest(Request('go')) client._prepare_request(request) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request) # Header set by argument self.assertEqual('application/json-rpc', request.prepped.headers['Content-Type']) # Header set by DEFAULT_HEADERS self.assertEqual('application/json', request.prepped.headers['Accept']) # Header set by Requests default_headers self.assertIn('Content-Length', request.prepped.headers)
def test_connection_error(self): client = HTTPClient('http://test/') request = PreparedRequest(Request('go')) client._prepare_request(request) with self.assertRaises(requests.exceptions.RequestException): client._send_message(request)