diff --git a/openphoto/api_album.py b/openphoto/api_album.py index e997b65..f2f2644 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() diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index fed9c8a..2c18e8e 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 """ diff --git a/openphoto/api_tag.py b/openphoto/api_tag.py index 89f9fee..5f3c676 100644 --- a/openphoto/api_tag.py +++ b/openphoto/api_tag.py @@ -20,10 +20,14 @@ class ApiTag: return Tag(self._client, 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 965df9a..d85a780 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -39,9 +39,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 """ @@ -97,9 +102,14 @@ class Photo(OpenPhotoObject): class Tag(OpenPhotoObject): def delete(self, **kwds): - """ Delete this tag """ - self._openphoto.post("/tag/%s/delete.json" % self.id, **kwds) + """ + Delete this tag. + Returns True if successful. + Raises an OpenPhotoError if not. + """ + result = self._openphoto.post("/tag/%s/delete.json" % self.id, **kwds)["result"] self._replace_fields({}) + return result def update(self, **kwds): """ Update this tag with the specified parameters """ @@ -125,9 +135,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() 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_photos.py b/tests/test_photos.py index ffddbfe..04e216d 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() diff --git a/tests/test_tags.py b/tests/test_tags.py index 02ea449..7f06ed2 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -16,13 +16,13 @@ class TestTags(test_base.TestBase): self.assertIn(tag_name, self.client.tags.list()) # Delete the tag - self.client.tag.delete(tag_name) + self.assertTrue(self.client.tag.delete(tag_name)) # Check that the tag is now gone self.assertNotIn(tag_name, self.client.tags.list()) # Create and delete using the Tag object directly tag = self.client.tag.create(tag_name) - tag.delete() + self.assertTrue(tag.delete()) # Check that the tag is now gone self.assertNotIn(tag_name, self.client.tags.list())