コード例 #1
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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
コード例 #2
0
 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)
コード例 #3
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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)
コード例 #4
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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)
コード例 #8
0
 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)
コード例 #9
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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)
コード例 #10
0
 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)
コード例 #11
0
ファイル: test_http_client.py プロジェクト: bcb/jsonrpcclient
 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)
コード例 #12
0
 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)