Update delete endpoints to return True if successful.
If the operation isn't successful, the API returns an error code, which raises an OpenPhotoError exception.
This commit is contained in:
parent
306c8430ba
commit
e09f166743
7 changed files with 60 additions and 24 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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 """
|
||||
|
|
|
@ -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 """
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()])
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue