diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index 0686a88..63f815f 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -89,4 +89,13 @@ 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) + # The API doesn't currently return the transformed photo + # Uncomment the below once frontend issue #955 is resolved +# return photo diff --git a/openphoto/objects.py b/openphoto/objects.py index a2328bf..82b8250 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -85,8 +85,15 @@ 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"] + # The API doesn't currently return the transformed photo + # Uncomment the below once frontend issue #955 is resolved +# self._replace_fields(new_dict) class Tag(OpenPhotoObject): def delete(self, **kwds): diff --git a/tests/test_photos.py b/tests/test_photos.py index 68e9cac..e12d47a 100644 --- a/tests/test_photos.py +++ b/tests/test_photos.py @@ -152,6 +152,22 @@ 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) + + # Need an explicit update, since transform API doesn't return the rotated photo + # Remove the following line once Issue #955 is resolved + photo = self.client.photo.view(self.photos[0]) + + self.assertEqual(photo.rotation, "90") + + # Do the same using the Photo object directly + photo.transform(rotate=90) + + # Need an explicit update, since transform API doesn't return the rotated photo + # Remove the following line once Issue #955 is resolved + photo = self.client.photo.view(photo) + + self.assertEqual(photo.rotation, "180")