def test_initialization(self): api = catapi.CatApi(api_key=None) self.assertEqual(api.api_key, None) api = catapi.CatApi(api_key=API_KEY) self.assertTrue(api.api_key)
def test_get_favorite(self): """ Verifies that get_favorite is able to get favorites properly """ api = catapi.CatApi(api_key=API_KEY) favorite = self.run_coro(api.favorite("438", "automated test")) get_fav = self.run_coro(api.get_favorite(favorite)) self.assertEqual(get_fav.id, favorite) self.run_coro(api.delete_favorite(favorite))
def test_get_favorites(self): """ Verifies that favorites returns a list of favorite objects """ api = catapi.CatApi(api_key=API_KEY) favorite = self.run_coro(api.favorite("438", "automated test")) favorites = self.run_coro(api.get_favorites()) self.assertEqual(len(favorites), 1) self.run_coro(api.delete_favorite(favorite))
def test_search_breeds(self): """ Verifies that searching for breeds works without errors. """ api = catapi.CatApi(api_key=API_KEY) breed = self.run_coro(api.search_breeds("siamese")) self.assertEqual(len(breed), 1) breed = breed[0] self.assertEqual(breed.name, "Siamese")
def test_search_images(self): """ Verifies that the search functionality works with or without all keywords. """ # Get a single random image api = catapi.CatApi(api_key=API_KEY) image = self.run_coro(api.search_images()) self.assertTrue(image[0].url)
def test_delete_favorite(self): """ Verifies that deleting favorites works """ api = catapi.CatApi(api_key=API_KEY) favorite = self.run_coro(api.favorite("438", "automated test")) favorites = self.run_coro(api.get_favorites()) self.assertEqual(len(favorites), 1) self.run_coro(api.delete_favorite(favorite)) favorites = self.run_coro(api.get_favorites()) self.assertEqual(len(favorites), 0)
def test_get_categories(self): """ Verifies that categories returns the appropriate amount of categories """ api = catapi.CatApi(api_key=API_KEY) categories = self.run_coro(api.get_categories()) self.assertEqual(len(categories), 7) categories = self.run_coro(api.get_categories(limit=2)) self.assertEqual(len(categories), 2)
def test_get_image(self): """ Ensures that image is able to return a single image """ api = catapi.CatApi(api_key=API_KEY) image_id = "e49" image = self.run_coro(api.get_image(image_id)) self.assertEqual(image.width, 500) self.assertEqual(image.height, 374) self.assertEqual(image.id, image_id)
def test_get_breeds(self): """ Verifies that breeds is searching for breeds properly """ api = catapi.CatApi(api_key=API_KEY) breeds = self.run_coro(api.get_breeds()) self.assertEqual(len(breeds), 5) breeds = self.run_coro(api.get_breeds(limit=2)) self.assertEqual(len(breeds), 2) self.assertTrue(breeds[0].name)
def test_get_uploads(self): """ Verifies that uploads are properly found. """ api = catapi.CatApi(api_key=API_KEY) uploads = self.run_coro(api.get_uploads()) self.assertEqual(len(uploads), 1) upload = uploads[0] self.assertEqual(upload.breed, None) self.assertEqual(upload.id, 'e3fZI02Ui') # I'm not sure if the url will change from time to time self.assertTrue(upload.url) self.assertEqual(upload.width, 640) self.assertEqual(upload.height, 480) self.assertEqual(upload.sub_id, None) self.assertEqual(upload.created_at, '2020-04-23T19:27:59.000Z') self.assertEqual(upload.original_filename, 'cat.jpg')
def setUp(self): self.api = catapi.CatApi(api_key=API_KEY) self.loop = asyncio.new_event_loop()