def test_handle_api_response_200(self): """Validate a API 200 code.""" content = utils.wrap_content(u'{"some": "content"}', status_code=200) responses.add( responses.GET, self.URL, body=content, status=200, ) response = requests.get(self.URL) result = self.api.handle_response(response, content) data = result.get('response') self.assertEqual(data, {'some': 'content'})
def test_handle_api_response_30x(self): """Validate a API 30x code.""" content = utils.wrap_content(u'"Redirect"', status_code=301) responses.add( responses.GET, self.URL, body=content, status=200, ) response = requests.get(self.URL) self.assertRaises( exceptions.Redirection, self.api.handle_response, response, content, )
def test_handle_api_response_500(self): """Validate a API 500 code.""" content = utils.wrap_content(u'"Server Error"', status_code=500) responses.add( responses.GET, self.URL, body=content, status=200, ) response = requests.get(self.URL) self.assertRaises( exceptions.ServerError, self.api.handle_response, response, content, )
def test_handle_api_response_401(self): """Validate a API 401 code.""" content = utils.wrap_content(u'"Unauthorized access"', status_code=401) responses.add( responses.GET, self.URL, body=content, status=200, ) response = requests.get(self.URL) self.assertRaises( exceptions.UnauthorizedAccess, self.api.handle_response, response, content, )