Merge branch 'master' into apiv2_tags
Conflicts: openphoto/objects.py tests/test_tags.py
This commit is contained in:
commit
6d5fe4433c
8 changed files with 90 additions and 45 deletions
|
@ -20,11 +20,15 @@ class ApiAlbum:
|
||||||
return Album(self._client, result)
|
return Album(self._client, result)
|
||||||
|
|
||||||
def delete(self, album, **kwds):
|
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):
|
if not isinstance(album, Album):
|
||||||
album = Album(self._client, {"id": album})
|
album = Album(self._client, {"id": album})
|
||||||
album.delete(**kwds)
|
return album.delete(**kwds)
|
||||||
|
|
||||||
def form(self, album, **kwds):
|
def form(self, album, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -39,10 +43,7 @@ class ApiAlbum:
|
||||||
if not isinstance(album, Album):
|
if not isinstance(album, Album):
|
||||||
album = Album(self._client, {"id": album})
|
album = Album(self._client, {"id": album})
|
||||||
album.update(**kwds)
|
album.update(**kwds)
|
||||||
|
return album
|
||||||
# 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
|
|
||||||
|
|
||||||
def view(self, album, **kwds):
|
def view(self, album, **kwds):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -14,25 +14,38 @@ class ApiPhotos:
|
||||||
return [Photo(self._client, photo) for photo in photos]
|
return [Photo(self._client, photo) for photo in photos]
|
||||||
|
|
||||||
def update(self, photos, **kwds):
|
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"]:
|
if not self._client.post("/photos/update.json", ids=photos, **kwds)["result"]:
|
||||||
raise OpenPhotoError("Update response returned False")
|
raise OpenPhotoError("Update response returned False")
|
||||||
|
return True
|
||||||
|
|
||||||
def delete(self, photos, **kwds):
|
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"]:
|
if not self._client.post("/photos/delete.json", ids=photos, **kwds)["result"]:
|
||||||
raise OpenPhotoError("Delete response returned False")
|
raise OpenPhotoError("Delete response returned False")
|
||||||
|
return True
|
||||||
|
|
||||||
class ApiPhoto:
|
class ApiPhoto:
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self._client = client
|
self._client = client
|
||||||
|
|
||||||
def delete(self, photo, **kwds):
|
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):
|
if not isinstance(photo, Photo):
|
||||||
photo = Photo(self._client, {"id": photo})
|
photo = Photo(self._client, {"id": photo})
|
||||||
photo.delete(**kwds)
|
return photo.delete(**kwds)
|
||||||
|
|
||||||
def edit(self, photo, **kwds):
|
def edit(self, photo, **kwds):
|
||||||
""" Returns an HTML form to edit a photo """
|
""" Returns an HTML form to edit a photo """
|
||||||
|
@ -91,4 +104,11 @@ class ApiPhoto:
|
||||||
return photo.next_previous(**kwds)
|
return photo.next_previous(**kwds)
|
||||||
|
|
||||||
def transform(self, photo, **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
|
||||||
|
|
|
@ -19,10 +19,14 @@ class ApiTag:
|
||||||
return self._client.post("/tag/create.json", tag=tag, **kwds)["result"]
|
return self._client.post("/tag/create.json", tag=tag, **kwds)["result"]
|
||||||
|
|
||||||
def delete(self, tag, **kwds):
|
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):
|
if not isinstance(tag, Tag):
|
||||||
tag = Tag(self._client, {"id": tag})
|
tag = Tag(self._client, {"id": tag})
|
||||||
tag.delete(**kwds)
|
return tag.delete(**kwds)
|
||||||
|
|
||||||
def update(self, tag, **kwds):
|
def update(self, tag, **kwds):
|
||||||
""" Update a tag """
|
""" Update a tag """
|
||||||
|
|
|
@ -40,9 +40,14 @@ class OpenPhotoObject:
|
||||||
|
|
||||||
class Photo(OpenPhotoObject):
|
class Photo(OpenPhotoObject):
|
||||||
def delete(self, **kwds):
|
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({})
|
self._replace_fields({})
|
||||||
|
return result
|
||||||
|
|
||||||
def edit(self, **kwds):
|
def edit(self, **kwds):
|
||||||
""" Returns an HTML form to edit the photo """
|
""" Returns an HTML form to edit the photo """
|
||||||
|
@ -93,14 +98,24 @@ class Photo(OpenPhotoObject):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def transform(self, **kwds):
|
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):
|
class Tag(OpenPhotoObject):
|
||||||
def delete(self, **kwds):
|
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({})
|
self._replace_fields({})
|
||||||
|
return result
|
||||||
|
|
||||||
def update(self, **kwds):
|
def update(self, **kwds):
|
||||||
""" Update this tag with the specified parameters """
|
""" Update this tag with the specified parameters """
|
||||||
|
@ -126,9 +141,14 @@ class Album(OpenPhotoObject):
|
||||||
self.photos[i] = Photo(self._openphoto, photo)
|
self.photos[i] = Photo(self._openphoto, photo)
|
||||||
|
|
||||||
def delete(self, **kwds):
|
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({})
|
self._replace_fields({})
|
||||||
|
return result
|
||||||
|
|
||||||
def form(self, **kwds):
|
def form(self, **kwds):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
@ -143,14 +163,8 @@ class Album(OpenPhotoObject):
|
||||||
""" Update this album with the specified parameters """
|
""" Update this album with the specified parameters """
|
||||||
new_dict = self._openphoto.post("/album/%s/update.json" % self.id,
|
new_dict = self._openphoto.post("/album/%s/update.json" % self.id,
|
||||||
**kwds)["result"]
|
**kwds)["result"]
|
||||||
|
self._replace_fields(new_dict)
|
||||||
# Since the API doesn't give us the modified album, we need to
|
self._update_fields_with_objects()
|
||||||
# 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()
|
|
||||||
|
|
||||||
def view(self, **kwds):
|
def view(self, **kwds):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -15,13 +15,13 @@ class TestAlbums(test_base.TestBase):
|
||||||
self.assertIn(album_name, [a.name for a in self.client.albums.list()])
|
self.assertIn(album_name, [a.name for a in self.client.albums.list()])
|
||||||
|
|
||||||
# Delete the album
|
# Delete the album
|
||||||
self.client.album.delete(album.id)
|
self.assertTrue(self.client.album.delete(album.id))
|
||||||
# Check that the album is now gone
|
# Check that the album is now gone
|
||||||
self.assertNotIn(album_name, [a.name for a in self.client.albums.list()])
|
self.assertNotIn(album_name, [a.name for a in self.client.albums.list()])
|
||||||
|
|
||||||
# Create it again, and delete it using the Album object
|
# Create it again, and delete it using the Album object
|
||||||
album = self.client.album.create(album_name)
|
album = self.client.album.create(album_name)
|
||||||
album.delete()
|
self.assertTrue(album.delete())
|
||||||
# Check that the album is now gone
|
# Check that the album is now gone
|
||||||
self.assertNotIn(album_name, [a.name for a in self.client.albums.list()])
|
self.assertNotIn(album_name, [a.name for a in self.client.albums.list()])
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ class TestBase(unittest.TestCase):
|
||||||
self.photos = self.client.photos.list()
|
self.photos = self.client.photos.list()
|
||||||
if len(self.photos) != 3:
|
if len(self.photos) != 3:
|
||||||
# print self.photos
|
# print self.photos
|
||||||
print "[Regenerating Photos]"
|
print "\n[Regenerating Photos]"
|
||||||
if len(self.photos) > 0:
|
if len(self.photos) > 0:
|
||||||
self._delete_all()
|
self._delete_all()
|
||||||
self._create_test_photos()
|
self._create_test_photos()
|
||||||
|
@ -79,7 +79,7 @@ class TestBase(unittest.TestCase):
|
||||||
if (len(self.tags) != 1 or
|
if (len(self.tags) != 1 or
|
||||||
self.tags[0].id != self.TEST_TAG or
|
self.tags[0].id != self.TEST_TAG or
|
||||||
self.tags[0].count != 3):
|
self.tags[0].count != 3):
|
||||||
print "[Regenerating Tags]"
|
print "\n[Regenerating Tags]"
|
||||||
self._delete_all()
|
self._delete_all()
|
||||||
self._create_test_photos()
|
self._create_test_photos()
|
||||||
self.photos = self.client.photos.list()
|
self.photos = self.client.photos.list()
|
||||||
|
@ -92,7 +92,7 @@ class TestBase(unittest.TestCase):
|
||||||
if (len(self.albums) != 1 or
|
if (len(self.albums) != 1 or
|
||||||
self.albums[0].name != self.TEST_ALBUM or
|
self.albums[0].name != self.TEST_ALBUM or
|
||||||
self.albums[0].count != "3"):
|
self.albums[0].count != "3"):
|
||||||
print "[Regenerating Albums]"
|
print "\n[Regenerating Albums]"
|
||||||
self._delete_all()
|
self._delete_all()
|
||||||
self._create_test_photos()
|
self._create_test_photos()
|
||||||
self.photos = self.client.photos.list()
|
self.photos = self.client.photos.list()
|
||||||
|
|
|
@ -6,11 +6,11 @@ class TestPhotos(test_base.TestBase):
|
||||||
def test_delete_upload(self):
|
def test_delete_upload(self):
|
||||||
""" Test photo deletion and upload """
|
""" Test photo deletion and upload """
|
||||||
# Delete one photo using the OpenPhoto class, passing in the id
|
# 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
|
# 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
|
# And another using the Photo object directly
|
||||||
self.photos[2].delete()
|
self.assertTrue(self.photos[2].delete())
|
||||||
|
|
||||||
# Check that they're gone
|
# Check that they're gone
|
||||||
self.assertEqual(self.client.photos.list(), [])
|
self.assertEqual(self.client.photos.list(), [])
|
||||||
|
@ -32,7 +32,7 @@ class TestPhotos(test_base.TestBase):
|
||||||
self.assertIn(ret_val.pathOriginal, pathOriginals)
|
self.assertIn(ret_val.pathOriginal, pathOriginals)
|
||||||
|
|
||||||
# Delete all photos in one go
|
# Delete all photos in one go
|
||||||
self.client.photos.delete(self.photos)
|
self.assertTrue(self.client.photos.delete(self.photos))
|
||||||
|
|
||||||
# Check they're gone
|
# Check they're gone
|
||||||
self.photos = self.client.photos.list()
|
self.photos = self.client.photos.list()
|
||||||
|
@ -147,6 +147,12 @@ class TestPhotos(test_base.TestBase):
|
||||||
self.client.photo.dynamic_url(None)
|
self.client.photo.dynamic_url(None)
|
||||||
|
|
||||||
def test_transform(self):
|
def test_transform(self):
|
||||||
""" If photo.transform gets implemented, write a test! """
|
""" Test photo rotation """
|
||||||
with self.assertRaises(openphoto.NotImplementedError):
|
photo = self.photos[0]
|
||||||
self.client.photo.transform(None)
|
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")
|
||||||
|
|
|
@ -16,14 +16,14 @@ class TestTags(test_base.TestBase):
|
||||||
self.assertIn(tag_id, [t.id for t in self.client.tags.list()])
|
self.assertIn(tag_id, [t.id for t in self.client.tags.list()])
|
||||||
|
|
||||||
# Delete the tag
|
# Delete the tag
|
||||||
self.client.tag.delete(tag_id)
|
self.assertTrue(self.client.tag.delete(tag_id))
|
||||||
# Check that the tag is now gone
|
# Check that the tag is now gone
|
||||||
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
|
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
|
||||||
|
|
||||||
# Create then delete using the Tag object directly
|
# Create then delete using the Tag object directly
|
||||||
self.photos[0].update(tagsAdd=tag_id)
|
self.photos[0].update(tagsAdd=tag_id)
|
||||||
tag = [t for t in self.client.tags.list() if t.id == tag_id][0]
|
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
|
# Check that the tag is now gone
|
||||||
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
|
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue