Exemplo n.º 1
0
 def test_start_finish_response_status_fail(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.start_response(404, {'error': 'not found'})
     responder.finish_response()
     self.assertEqual('404 Not Found', self.status)
     self.assertEqual({'content-type': 'application/json',
                       'cache-control': 'no-cache'}, self.headers)
     self.assertEqual(['{"error": "not found"}\r\n'], self.response_body)
     self.assertEqual([], responder.content)
Exemplo n.º 2
0
 def test_send_response_content_w_headers(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.send_response_content('foo', headers={'x-a': '1'})
     self.assertEqual('200 OK', self.status)
     self.assertEqual({'content-type': 'application/json',
                       'cache-control': 'no-cache',
                       'x-a': '1', 'content-length': '3'}, self.headers)
     self.assertEqual([], self.response_body)
     self.assertEqual(['foo'], responder.content)
Exemplo n.º 3
0
 def test_send_response_json_status_fail(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.send_response_json(400)
     self.assertEqual('400 Bad Request', self.status)
     expected_body = '{}\r\n'
     self.assertEqual({'content-type': 'application/json',
                       'content-length': str(len(expected_body)),
                       'cache-control': 'no-cache'}, self.headers)
     self.assertEqual([], self.response_body)
     self.assertEqual([expected_body], responder.content)
Exemplo n.º 4
0
 def test_send_response_json(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.send_response_json(value='success')
     self.assertEqual('200 OK', self.status)
     expected_body = '{"value": "success"}\r\n'
     self.assertEqual({'content-type': 'application/json',
                       'content-length': str(len(expected_body)),
                       'cache-control': 'no-cache'}, self.headers)
     self.assertEqual([], self.response_body)
     self.assertEqual([expected_body], responder.content)
Exemplo n.º 5
0
 def test_send_stream_w_error(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.content_type = "application/x-u1db-multi-json"
     responder.start_response(200)
     responder.start_stream()
     responder.stream_entry({'entry': 1})
     responder.send_response_json(503, error="unavailable")
     self.assertEqual('200 OK', self.status)
     self.assertEqual({'content-type': 'application/x-u1db-multi-json',
                       'cache-control': 'no-cache'}, self.headers)
     self.assertEqual(['[',
                       '\r\n', '{"entry": 1}'], self.response_body)
     self.assertEqual([',\r\n', '{"error": "unavailable"}\r\n'],
                      responder.content)
Exemplo n.º 6
0
 def test_send_stream_entry(self):
     responder = http_app.HTTPResponder(self.start_response)
     responder.content_type = "application/x-u1db-multi-json"
     responder.start_response(200)
     responder.start_stream()
     responder.stream_entry({'entry': 1})
     responder.stream_entry({'entry': 2})
     responder.end_stream()
     responder.finish_response()
     self.assertEqual('200 OK', self.status)
     self.assertEqual({'content-type': 'application/x-u1db-multi-json',
                       'cache-control': 'no-cache'}, self.headers)
     self.assertEqual(['[',
                       '\r\n', '{"entry": 1}',
                       ',\r\n', '{"entry": 2}',
                       '\r\n]\r\n'], self.response_body)
     self.assertEqual([], responder.content)