def test_bango_portal_redirect_api_error(self, api): self.setup_bango_portal() err = {'errors': 'Something went wrong.'} api.bango.login.post.side_effect = HttpClientError(content=err) res = self.client.get(self.portal_url) eq_(res.status_code, 400) eq_(json.loads(res.content), err)
def test_bango_portal_redirect_api_error(self, api): message = 'Something went wrong.' error = {'__all__': [message]} api.bango.login.post.side_effect = HttpClientError(content=error) res = self.client.get(self.portal_url, follow=True) eq_(res.redirect_chain, [('http://testserver/lookup/', 302)]) ok_(message in [msg.message for msg in res.context['messages']][0])
def test_create_fail(self): err = {'broken': True} self.bango_patcher.package.post.side_effect = HttpClientError( content=err) res = self.client.post(self.payment_list, data=json.dumps(payment_data)) eq_(res.status_code, 500) eq_(json.loads(res.content), err)
def test_add_fail(self, client): err = {'broken': True} client.api.bango.package.post.side_effect = HttpClientError( content=err) r = self.client.post(list_url('account'), data=json.dumps(payment_data)) eq_(r.status_code, 500) eq_(json.loads(r.content), err)
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'})
def test_fail(self, sol, mkt): error = HttpClientError(response=HttpResponse()) sol.services.request.get.return_value = {'authenticated': 'webpay'} mkt.account.permissions.mine.get.side_effect = error res = self.client.get(self.url) eq_(res.status_code, 500)