From 4147029b14b65a07a6fc44241b97d30140018777 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Mon, 10 Sep 2012 23:57:42 +0100 Subject: [PATCH 1/5] 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") From 07745f149659918e40600e636a5c6049fb240346 Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sat, 23 Mar 2013 16:45:24 +0000 Subject: [PATCH 2/5] Frontend issue 937 is now resolved - album.update now returns the updated album --- openphoto/api_album.py | 7 ++----- openphoto/objects.py | 10 ++-------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/openphoto/api_album.py b/openphoto/api_album.py index e997b65..cda3687 100644 --- a/openphoto/api_album.py +++ b/openphoto/api_album.py @@ -1,4 +1,4 @@ -from errors import * +< Date: Sat, 23 Mar 2013 16:46:47 +0000 Subject: [PATCH 3/5] Prettier printout when running tests --- tests/test_base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_base.py b/tests/test_base.py index 9f89315..a905bbf 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -62,7 +62,7 @@ class TestBase(unittest.TestCase): self.photos = self.client.photos.list() if len(self.photos) != 3: # print self.photos - print "[Regenerating Photos]" + print "\n[Regenerating Photos]" if len(self.photos) > 0: self._delete_all() self._create_test_photos() @@ -72,7 +72,7 @@ class TestBase(unittest.TestCase): if (len(self.tags) != 1 or self.tags[0].id != self.TEST_TAG or self.tags[0].count != 3): - print "[Regenerating Tags]" + print "\n[Regenerating Tags]" self._delete_all() self._create_test_photos() self.photos = self.client.photos.list() @@ -85,7 +85,7 @@ class TestBase(unittest.TestCase): if (len(self.albums) != 1 or self.albums[0].name != self.TEST_ALBUM or self.albums[0].count != "3"): - print "[Regenerating Albums]" + print "\n[Regenerating Albums]" self._delete_all() self._create_test_photos() self.photos = self.client.photos.list() From 1ce5192d70406cb4b9fc8db54db485f6144e964b Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sat, 23 Mar 2013 16:35:16 +0000 Subject: [PATCH 4/5] Fixed typo --- openphoto/api_album.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openphoto/api_album.py b/openphoto/api_album.py index cda3687..55e734f 100644 --- a/openphoto/api_album.py +++ b/openphoto/api_album.py @@ -1,4 +1,4 @@ -< Date: Sat, 13 Apr 2013 13:11:26 +0100 Subject: [PATCH 5/5] Not that frontend issue 955 is resolved, we should use the return value of the transform API to replace the photo object's fields --- openphoto/api_photo.py | 4 +--- openphoto/objects.py | 6 ++---- tests/test_photos.py | 10 ---------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index 6e26ea8..18ae68c 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -111,6 +111,4 @@ class ApiPhoto: 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 + return photo diff --git a/openphoto/objects.py b/openphoto/objects.py index 17484f5..1d09f43 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -98,14 +98,12 @@ class Photo(OpenPhotoObject): def transform(self, **kwds): """ - Performs transformation specified in **kwds + 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) + 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 8c48e53..0050298 100644 --- a/tests/test_photos.py +++ b/tests/test_photos.py @@ -151,18 +151,8 @@ class TestPhotos(test_base.TestBase): 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")