Add photo.transform support and testcase.

This commit is contained in:
sneakypete81 2012-09-10 23:57:42 +01:00
parent b900b2abd3
commit 4147029b14
3 changed files with 38 additions and 6 deletions

View file

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

View file

@ -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):

View file

@ -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")