Example #1
0
 def test_unknown_error_responses(self):
     # Create a scenario where the proxied API raises an HTTP error.
     data = {"unknown_error": "something went wrong"}
     proxy_res = HttpResponse(data, content_type="application/json", status=403)
     proxy_res.json = data
     proxy_res.request = RequestFactory().get("http://api/some/endpoint")
     exc = HttpClientError(proxy_res.content, response=proxy_res)
     self.api.products.get.side_effect = exc
     res = self.request("get", "/reference/products?foo=bar", "products")
     eq_(res.status_code, 403)
     eq_(res.json, {u"error_message": {u"unknown_error": u"something went wrong"}})
 def test_proxy_error_responses(self):
     # Create a scenario where the proxied API raises an HTTP error.
     data = {'error': {'message': 'something not found'}}
     proxy_res = HttpResponse(data,
                              content_type='application/json',
                              status=404)
     proxy_res.json = data
     proxy_res.request = RequestFactory().get('http://api/some/endpoint')
     exc = HttpClientError(proxy_res.content, response=proxy_res)
     self.api.products.get.side_effect = exc
     res = self.request('get', '/reference/products?foo=bar', 'products')
     eq_(res.status_code, 404)
     eq_(json.loads(res.content), {'error_message': 'something not found'})
Example #3
0
 def test_proxy_error_responses(self):
     # Create a scenario where the proxied API raises an HTTP error.
     data = {'error': {'message': 'something not found'}}
     proxy_res = HttpResponse(data,
                              content_type='application/json',
                              status=404)
     proxy_res.json = data
     proxy_res.request = RequestFactory().get('http://api/some/endpoint')
     exc = HttpClientError(proxy_res.content, response=proxy_res)
     self.api.products.get.side_effect = exc
     res = self.request('get', '/reference/products?foo=bar', 'products')
     eq_(res.status_code, 404)
     eq_(res.json, {'error_message': 'something not found'})
Example #4
0
 def view(req):
     response = HttpResponse()
     response.request = req
     return response
Example #5
0
def mock_response(request):
    response = HttpResponse()
    response.request = request
    return response
 def pass_through(request,owner_name):
   resp = HttpResponse()
   resp.request = request
   return resp