Merge branch 'master' into apiv2_tags

Conflicts:
	openphoto/objects.py
	tests/test_tags.py
This commit is contained in:
sneakypete81 2013-04-28 15:29:33 +01:00
commit 6d5fe4433c
8 changed files with 90 additions and 45 deletions

View file

@ -20,10 +20,14 @@ 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):
"""

View file

@ -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

View file

@ -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 """

View file

@ -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):
"""

View file

@ -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()])

View file

@ -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()

View file

@ -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")

View file

@ -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()])