diff --git a/openphoto/api_album.py b/openphoto/api_album.py index e997b65..9777a30 100644 --- a/openphoto/api_album.py +++ b/openphoto/api_album.py @@ -20,11 +20,15 @@ class ApiAlbum: return Album(self._client, result) def delete(self, album, **kwds): - """ Delete an album """ + """ + Delete an album. + Returns True if successful. + Raises an OpenPhotoError if not. + """ if not isinstance(album, Album): album = Album(self._client, {"id": album}) - album.delete(**kwds) - + return album.delete(**kwds) + def form(self, album, **kwds): raise NotImplementedError() @@ -39,10 +43,7 @@ class ApiAlbum: if not isinstance(album, Album): album = Album(self._client, {"id": album}) album.update(**kwds) - - # Don't return the album, since the API currently doesn't give us the modified album - # TODO: Uncomment the following once frontend issue #937 is resolved -# return album + return album def view(self, album, **kwds): """ diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index fed9c8a..18ae68c 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -14,25 +14,38 @@ class ApiPhotos: return [Photo(self._client, photo) for photo in photos] def update(self, photos, **kwds): - """ Updates a list of photos """ + """ + Updates a list of photos. + Returns True if successful. + Raises OpenPhotoError if not. + """ if not self._client.post("/photos/update.json", ids=photos, **kwds)["result"]: raise OpenPhotoError("Update response returned False") + return True def delete(self, photos, **kwds): - """ Deletes a list of photos """ + """ + Deletes a list of photos. + Returns True if successful. + Raises OpenPhotoError if not. + """ if not self._client.post("/photos/delete.json", ids=photos, **kwds)["result"]: raise OpenPhotoError("Delete response returned False") - + return True class ApiPhoto: def __init__(self, client): self._client = client def delete(self, photo, **kwds): - """ Delete a photo """ + """ + Delete a photo. + Returns True if successful. + Raises an OpenPhotoError if not. + """ if not isinstance(photo, Photo): photo = Photo(self._client, {"id": photo}) - photo.delete(**kwds) + return photo.delete(**kwds) def edit(self, photo, **kwds): """ Returns an HTML form to edit a photo """ @@ -91,4 +104,11 @@ class ApiPhoto: return photo.next_previous(**kwds) def transform(self, photo, **kwds): - raise NotImplementedError() + """ + Performs transformation specified in **kwds + Example: transform(photo, rotate=90) + """ + if not isinstance(photo, Photo): + photo = Photo(self._client, {"id": photo}) + photo.transform(**kwds) + return photo diff --git a/openphoto/api_tag.py b/openphoto/api_tag.py index 464cc9d..bc87d32 100644 --- a/openphoto/api_tag.py +++ b/openphoto/api_tag.py @@ -19,10 +19,14 @@ class ApiTag: return self._client.post("/tag/create.json", tag=tag, **kwds)["result"] def delete(self, tag, **kwds): - """ Delete a tag """ + """ + Delete a tag. + Returns True if successful. + Raises an OpenPhotoError if not. + """ if not isinstance(tag, Tag): tag = Tag(self._client, {"id": tag}) - tag.delete(**kwds) + return tag.delete(**kwds) def update(self, tag, **kwds): """ Update a tag """ diff --git a/openphoto/objects.py b/openphoto/objects.py index 062ed92..c790ed5 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -40,9 +40,14 @@ class OpenPhotoObject: class Photo(OpenPhotoObject): def delete(self, **kwds): - """ Delete this photo """ - self._openphoto.post("/photo/%s/delete.json" % self.id, **kwds) + """ + Delete this photo. + Returns True if successful. + Raises an OpenPhotoError if not. + """ + result = self._openphoto.post("/photo/%s/delete.json" % self.id, **kwds)["result"] self._replace_fields({}) + return result def edit(self, **kwds): """ Returns an HTML form to edit the photo """ @@ -93,14 +98,24 @@ class Photo(OpenPhotoObject): return value def transform(self, **kwds): - raise NotImplementedError() - + """ + Performs transformation specified in **kwds + Example: transform(rotate=90) + """ + new_dict = self._openphoto.post("/photo/%s/transform.json" % self.id, + **kwds)["result"] + self._replace_fields(new_dict) class Tag(OpenPhotoObject): def delete(self, **kwds): - """ Delete this tag """ - self._openphoto.post("/tag/%s/delete.json" % urllib.quote(self.id), **kwds) + """ + Delete this tag. + Returns True if successful. + Raises an OpenPhotoError if not. + """ + result = self._openphoto.post("/tag/%s/delete.json" % urllib.quote(self.id), **kwds)["result"] self._replace_fields({}) + return result def update(self, **kwds): """ Update this tag with the specified parameters """ @@ -126,9 +141,14 @@ class Album(OpenPhotoObject): self.photos[i] = Photo(self._openphoto, photo) def delete(self, **kwds): - """ Delete this album """ - self._openphoto.post("/album/%s/delete.json" % self.id, **kwds) + """ + Delete this album. + Returns True if successful. + Raises an OpenPhotoError if not. + """ + result = self._openphoto.post("/album/%s/delete.json" % self.id, **kwds)["result"] self._replace_fields({}) + return result def form(self, **kwds): raise NotImplementedError() @@ -143,14 +163,8 @@ class Album(OpenPhotoObject): """ Update this album with the specified parameters """ new_dict = self._openphoto.post("/album/%s/update.json" % self.id, **kwds)["result"] - - # Since the API doesn't give us the modified album, we need to - # update our fields based on the kwds that were sent - self._set_fields(kwds) - - # Replace the above line with the below once frontend issue #937 is resolved -# self._set_fields(new_dict) -# self._update_fields_with_objects() + self._replace_fields(new_dict) + self._update_fields_with_objects() def view(self, **kwds): """ diff --git a/tests/test_albums.py b/tests/test_albums.py index 53ff7e9..563660f 100644 --- a/tests/test_albums.py +++ b/tests/test_albums.py @@ -15,13 +15,13 @@ class TestAlbums(test_base.TestBase): self.assertIn(album_name, [a.name for a in self.client.albums.list()]) # Delete the album - self.client.album.delete(album.id) + 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) - album.delete() + self.assertTrue(album.delete()) # Check that the album is now gone self.assertNotIn(album_name, [a.name for a in self.client.albums.list()]) diff --git a/tests/test_base.py b/tests/test_base.py index ad425b1..1365c88 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -69,7 +69,7 @@ class TestBase(unittest.TestCase): self.photos = self.client.photos.list() if len(self.photos) != 3: # print self.photos - print "[Regenerating Photos]" + print "\n[Regenerating Photos]" if len(self.photos) > 0: self._delete_all() self._create_test_photos() @@ -79,7 +79,7 @@ class TestBase(unittest.TestCase): if (len(self.tags) != 1 or self.tags[0].id != self.TEST_TAG or self.tags[0].count != 3): - print "[Regenerating Tags]" + print "\n[Regenerating Tags]" self._delete_all() self._create_test_photos() self.photos = self.client.photos.list() @@ -92,7 +92,7 @@ class TestBase(unittest.TestCase): if (len(self.albums) != 1 or self.albums[0].name != self.TEST_ALBUM or self.albums[0].count != "3"): - print "[Regenerating Albums]" + print "\n[Regenerating Albums]" self._delete_all() self._create_test_photos() self.photos = self.client.photos.list() diff --git a/tests/test_photos.py b/tests/test_photos.py index ffddbfe..0050298 100644 --- a/tests/test_photos.py +++ b/tests/test_photos.py @@ -6,11 +6,11 @@ class TestPhotos(test_base.TestBase): def test_delete_upload(self): """ Test photo deletion and upload """ # Delete one photo using the OpenPhoto class, passing in the id - self.client.photo.delete(self.photos[0].id) + self.assertTrue(self.client.photo.delete(self.photos[0].id)) # Delete one photo using the OpenPhoto class, passing in the object - self.client.photo.delete(self.photos[1]) + self.assertTrue(self.client.photo.delete(self.photos[1])) # And another using the Photo object directly - self.photos[2].delete() + self.assertTrue(self.photos[2].delete()) # Check that they're gone self.assertEqual(self.client.photos.list(), []) @@ -32,7 +32,7 @@ class TestPhotos(test_base.TestBase): self.assertIn(ret_val.pathOriginal, pathOriginals) # Delete all photos in one go - self.client.photos.delete(self.photos) + self.assertTrue(self.client.photos.delete(self.photos)) # Check they're gone self.photos = self.client.photos.list() @@ -147,6 +147,12 @@ class TestPhotos(test_base.TestBase): self.client.photo.dynamic_url(None) def test_transform(self): - """ If photo.transform gets implemented, write a test! """ - with self.assertRaises(openphoto.NotImplementedError): - self.client.photo.transform(None) + """ Test photo rotation """ + photo = self.photos[0] + self.assertEqual(photo.rotation, "0") + photo = self.client.photo.transform(photo, rotate=90) + self.assertEqual(photo.rotation, "90") + + # Do the same using the Photo object directly + photo.transform(rotate=90) + self.assertEqual(photo.rotation, "180") diff --git a/tests/test_tags.py b/tests/test_tags.py index a90e744..cf560b1 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -16,14 +16,14 @@ class TestTags(test_base.TestBase): self.assertIn(tag_id, [t.id for t in self.client.tags.list()]) # Delete the tag - self.client.tag.delete(tag_id) + self.assertTrue(self.client.tag.delete(tag_id)) # Check that the tag is now gone self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()]) # Create then delete using the Tag object directly self.photos[0].update(tagsAdd=tag_id) tag = [t for t in self.client.tags.list() if t.id == tag_id][0] - tag.delete() + self.assertTrue(tag.delete()) # Check that the tag is now gone self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])