def test_specified_api_version(self): """ For all API versions >0, we get a generic hello world message """ for api_version in range(1, test_base.get_test_server_api() + 1): client = trovebox.Trovebox(config_file=self.config_file, api_version=api_version) result = client.get("hello.json") self.assertEqual(result["message"], "Hello, world!") self.assertEqual(result["result"]["__route__"], "/v%d/hello.json" % api_version)
def test_specified_api_version(self): """ For all API versions >0, we get a generic hello world message """ for api_version in range(1, test_base.get_test_server_api() + 1): client = trovebox.Trovebox(config_file=self.config_file) client.configure(api_version=api_version) result = client.get("hello.json") self.assertEqual(result['message'], "Hello, world!") self.assertEqual(result['result']['__route__'], "/v%d/hello.json" % api_version)
try: import unittest2 as unittest except ImportError: import unittest from tests.functional import test_base, test_activities, test_actions from tests.functional import test_albums, test_photos, test_tags @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestActivitiesV2(test_activities.TestActivities): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestActionsV2(test_actions.TestActions): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestAlbumsV2(test_albums.TestAlbums): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestPhotosV2(test_photos.TestPhotos): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestTagsV2(test_tags.TestTags):
class TestAlbums(test_base.TestBase): testcase_name = "album API" def test_create_delete(self): """ Create an album then delete it """ album_name = "create_delete_album" album = self.client.album.create(album_name) # Check the return value self.assertEqual(album.name, album_name) # Check that the album now exists self.assertIn(album_name, [a.name for a in self.client.albums.list()]) # Delete the album self.assertTrue(self.client.album.delete(album.id)) # Check that the album is now gone self.assertNotIn(album_name, [a.name for a in self.client.albums.list()]) # Create it again, and delete it using the Album object album = self.client.album.create(album_name) self.assertTrue(album.delete()) # Check that the album is now gone self.assertNotIn(album_name, [a.name for a in self.client.albums.list()]) def test_update(self): """ Test that an album can be updated """ # Update the album using the Trovebox class, # passing in the album object new_name = "New Name" self.client.album.update(self.albums[0], name=new_name) # Check that the album is updated self.albums = self.client.albums.list() self.assertEqual(self.albums[0].name, new_name) # Update the album using the Trovebox class, passing in the album id new_name = "Another New Name" self.client.album.update(self.albums[0].id, name=new_name) # Check that the album is updated self.albums = self.client.albums.list() self.assertEqual(self.albums[0].name, new_name) # Update the album using the Album object directly self.albums[0].update(name=self.TEST_ALBUM) # Check that the album is updated self.albums = self.client.albums.list() self.assertEqual(self.albums[0].name, self.TEST_ALBUM) @unittest.skipIf(test_base.get_test_server_api() == 1, "update_cover was introduced in APIv2") def test_update_cover(self): """ Test that an album cover can be updated """ self.albums[0].cover_update(self.photos[0]) self.assertNotEqual(self.albums[0].cover.id, self.photos[1].id) self.albums[0].cover_update(self.photos[1]) self.assertEqual(self.albums[0].cover.id, self.photos[1].id) @unittest.skipIf(test_base.get_test_server_api() == 1, "includeElements was introduced in APIv2") def test_view(self): """ Test the album view """ # Do a view() with includeElements=False, using a fresh Album object album = Album(self.client, {"id": self.albums[0].id}) album.view() # Make sure there are no photos reported self.assertEqual(album.photos, None) # Get the photos with includeElements=True album.view(includeElements=True) # Make sure all photos are in the album for photo in self.photos: self.assertIn(photo.id, [p.id for p in album.photos]) def test_add_remove(self): """ Test that photos can be added and removed from an album """ # Make sure all photos are in the album album = self.albums[0] album.view(includeElements=True) for photo in self.photos: self.assertIn(photo.id, [p.id for p in album.photos]) # Remove two photos and check that they're gone album.remove(self.photos[:2]) album.view(includeElements=True) self.assertEqual([p.id for p in album.photos], [self.photos[2].id]) # Add a photo and check that it's there album.add(self.photos[1]) album.view(includeElements=True) self.assertNotIn(self.photos[0].id, [p.id for p in album.photos]) self.assertIn(self.photos[1].id, [p.id for p in album.photos]) self.assertIn(self.photos[2].id, [p.id for p in album.photos]) # Put the environment back the way we found it album.add(self.photos[0])
try: import unittest2 as unittest except ImportError: import unittest from tests.functional import test_base, test_albums, test_photos, test_tags @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestAlbumsV2(test_albums.TestAlbums): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestPhotosV2(test_photos.TestPhotos): api_version = 2 @unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestTagsV2(test_tags.TestTags): api_version = 2
try: import unittest2 as unittest # Python2.6 except ImportError: import unittest from tests.functional import test_base @unittest.skipIf(test_base.get_test_server_api() == 1, "The tag API didn't work at v1 - see frontend issue #927") class TestTags(test_base.TestBase): testcase_name = "tag API" def test_create_delete(self, tag_id="create_tag"): """ Create a tag then delete it. This test is a little contrived, since the tag create/delete endpoints are only intended for internal use. """ # Create a tag self.assertTrue(self.client.tag.create(tag_id)) # Check that the tag doesn't exist (It has no photos, so it's invisible) self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()]) # Create a tag on one of the photos self.photos[0].update(tagsAdd=tag_id) # Check that the tag now exists self.assertIn(tag_id, [t.id for t in self.client.tags.list()]) # Delete the tag self.assertTrue(self.client.tag.delete(tag_id)) # Check that the tag is now gone