From 4147029b14b65a07a6fc44241b97d30140018777 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Mon, 10 Sep 2012 23:57:42 +0100 Subject: [PATCH] Add photo.transform support and testcase. --- openphoto/api_photo.py | 11 ++++++++++- openphoto/objects.py | 11 +++++++++-- tests/test_photos.py | 22 +++++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) 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")