class TestShortenAPI(unittest.TestCase): def setUp(self): self.api = API() @patch_object(API, "_invoke_api", mocked_API_request_failure(200)) def test_shorten_api_response_200(self): api_response = self.api.shorten("http://www.bernardofontes.net") self.assertEquals(api_response["status_code"], 200) self.assertTrue(api_response.has_key("url")) self.assertTrue(api_response["url"]) @patch_object(API, "_invoke_api", mocked_API_request_failure(403)) def test_shorten_api_response_403(self): api_response = self.api.shorten("http://www.bernardofontes.net") self.assertEquals(api_response["status_code"], 403) self.assertTrue(api_response.has_key("error_message")) self.assertTrue("Rate limit exceeded" in api_response["error_message"]) @patch_object(API, "_invoke_api", mocked_API_request_failure(503)) def test_shorten_api_response_503(self): api_response = self.api.shorten("http://www.bernardofontes.net") self.assertEquals(api_response["status_code"], 503) self.assertTrue(api_response.has_key("error_message")) self.assertTrue("Unknow error or temporary unavailability" in api_response["error_message"]) @patch_object(API, "_invoke_api", mocked_API_request_failure(500)) def test_shorten_api_response_500(self): api_response = self.api.shorten("http://www.bernardofontes.net") self.assertEquals(api_response["status_code"], 500) self.assertTrue(api_response.has_key("error_message")) self.assertTrue("Invalid request format" in api_response["error_message"])
class TestShortenAPI(unittest.TestCase): def setUp(self): self.api = API() @patch.object(API, '_invoke_api', mocked_shorten_API_response(200)) def test_shorten_api_response_200(self): api_response = self.api.shorten('http://www.bernardofontes.net') status_code = api_response['status_code'] self.assertEquals(status_code, 200) self.assertTrue(api_response.has_key('url')) self.assertTrue(api_response['url']) @patch.object(API, '_invoke_api', mocked_shorten_API_response(403)) def test_shorten_api_response_403(self): api_response = self.api.shorten('http://www.bernardofontes.net') status_code = api_response['status_code'] self.assertEquals(status_code, 403) self.assertTrue(api_response.has_key('error_message')) self.assertTrue('Rate limit exceeded' in api_response['error_message']) @patch.object(API, '_invoke_api', mocked_shorten_API_response(503)) def test_shorten_api_response_503(self): api_response = self.api.shorten('http://www.bernardofontes.net') status_code = api_response['status_code'] self.assertEquals(status_code, 503) self.assertTrue(api_response.has_key('error_message')) self.assertTrue('Unknow error or temporary unavailability' in api_response['error_message']) @patch.object(API, '_invoke_api', mocked_shorten_API_response(500)) def test_shorten_api_response_500(self): api_response = self.api.shorten('http://www.bernardofontes.net') status_code = api_response['status_code'] self.assertEquals(status_code, 500) self.assertTrue(api_response.has_key('error_message')) self.assertTrue('Invalid request format' in api_response['error_message'])