diff --git a/openphoto/api_album.py b/openphoto/api_album.py index f2f2644..9777a30 100644 --- a/openphoto/api_album.py +++ b/openphoto/api_album.py @@ -43,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): """ diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index 2c18e8e..18ae68c 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -104,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 diff --git a/openphoto/objects.py b/openphoto/objects.py index 78af7be..60bc2c9 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -107,8 +107,13 @@ 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): @@ -167,14 +172,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): """ diff --git a/tests/test_photos.py b/tests/test_photos.py index 0704220..183617f 100644 --- a/tests/test_photos.py +++ b/tests/test_photos.py @@ -149,6 +149,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")