Example #1
0
 def test_send_message_with_success_200():
     s = HTTPServer('http://test/')
     responses.add(responses.POST,
                   'http://test/',
                   status=200,
                   body='{"jsonrpc": "2.0", "result": 5, "id": 1}')
     s._send_message(Request('go'))
Example #2
0
 def test_ssl_verification(self):
     s = HTTPServer('https://test/')
     s.session.cert = '/path/to/cert'
     s.session.verify = 'ca-cert'
     req = Request('go')
     with self.assertRaises(requests.exceptions.RequestException):
         s._send_message(req)
Example #3
0
 def test_send_message_with_invalid_request(self):
     s = HTTPServer('http://test/')
     # 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):
         s._send_message(Request('go'))
Example #4
0
 def test_send_message_custom_headers(self):
     s = HTTPServer('http://test/')
     req = Request('go')
     with self.assertRaises(requests.exceptions.RequestException):
         s._send_message(req,
                         headers={'Content-Type': 'application/json-rpc'})
     # Header set by argument
     self.assertEqual('application/json-rpc',
                      s.last_request.headers['Content-Type'])
     # Header set by DEFAULT_HEADERS
     self.assertEqual('application/json', s.last_request.headers['Accept'])
     # Header set by Requests default_headers
     self.assertIn('Content-Length', s.last_request.headers)
Example #5
0
 def test_send_message_with_connection_error(self):
     s = HTTPServer('http://test/')
     with self.assertRaises(requests.exceptions.RequestException):
         s._send_message(Request('go'))
Example #6
0
 def test_send_message_body(self):
     s = HTTPServer('http://test/')
     req = Request('go')
     with self.assertRaises(requests.exceptions.RequestException):
         s._send_message(req)
     self.assertEqual(urlencode(req), s.last_request.body)