def test_response_repr(self): request_id = uuid.uuid4() data = self._response_data() response = Response(request_id, data, Mock()) self.assertEqual(repr(response), "Response('{}', {})".format(request_id, data))
def test_create_response(self): data = self._response_data() response = Response(uuid.uuid4(), data, Mock()) self.assertEqual(response.status_code, 200) self.assertEqual(response.reason, 'OK') self.assertEqual(len(response.headers), 2) self.assertEqual(response.headers['Content-Type'], 'application/json')
def test_load_response_body(self): mock_client = Mock() mock_client.get_response_body.return_value = b'the body' data = self._response_data() request_id = uuid.uuid4() response = Response(request_id, data, mock_client) body = response.body self.assertEqual(body, b'the body') mock_client.get_response_body.assert_called_once_with(request_id)
def test_load_response_body_uses_cached_data(self): mock_client = Mock() mock_client.get_response_body.return_value = b'the body' data = self._response_data() request_id = uuid.uuid4() response = Response(request_id, data, mock_client) response.body # Retrieves the body body = response.body # Uses the previously retrieved body self.assertEqual(body, b'the body') mock_client.get_response_body.assert_called_once_with(request_id)
def test_response_str(self): data = self._response_data() response = Response(uuid.uuid4(), data, Mock()) self.assertEqual(str(response), '200 OK'.format(data))
def test_get_header_case_insensitive(self): data = self._response_data() response = Response(uuid.uuid4(), data, Mock()) self.assertEqual(response.headers['content-type'], 'application/json')