Beispiel #1
0
    def test_400_error_default_with_proxied_text(self):
        view = ProxyView()
        view = self.get_view({'RETURN_RAW_ERROR': True})

        responses.add(responses.GET,
                      'http://sample',
                      body="error response text",
                      status=400)

        resp = requests.get('http://sample')
        proxy_resp = view.create_response(resp)

        self.assertEqual(proxy_resp.__class__.__name__, 'HttpResponse')
        self.assertEqual(proxy_resp.content, b'error response text')
        self.assertEqual(proxy_resp.status_code, 400)
        self.assertEqual(proxy_resp._headers['content-type'][1], 'text/plain')
Beispiel #2
0
    def test_400_error_default_with_proxied_json(self):
        view = ProxyView()
        view = self.get_view({'RETURN_RAW_ERROR': True})

        responses.add(responses.GET,
                      'http://sample',
                      json={'error': 'error response'},
                      status=400)

        resp = requests.get('http://sample')
        proxy_resp = view.create_response(resp)

        self.assertEqual(proxy_resp.__class__.__name__, 'HttpResponse')
        self.assertEqual(proxy_resp.content, b'{"error": "error response"}')
        self.assertEqual(proxy_resp.status_code, 400)
        self.assertEqual(proxy_resp._headers['content-type'][1],
                         'application/json')