Merge branch 'master' into api_versioning

Conflicts:
	tests/test_base.py
This commit is contained in:
sneakypete81 2013-04-28 15:42:22 +01:00
commit c7c3b4bdb5
4 changed files with 27 additions and 18 deletions

View file

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

View file

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

View file

@ -107,8 +107,13 @@ 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):
@ -167,14 +172,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):
""" """

View file

@ -149,6 +149,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")