Next/previous now returns a list of multiple photos (Issue #1004)

This commit is contained in:
Pete 2013-02-09 17:10:44 +00:00 committed by sneakypete81
parent 4ccdceb601
commit 895b98dedf
3 changed files with 16 additions and 9 deletions

View file

@ -81,8 +81,8 @@ class ApiPhoto:
def next_previous(self, photo, **kwds): def next_previous(self, photo, **kwds):
""" """
Returns a dict containing the next and previous photo objects, Returns a dict containing the next and previous photo lists
given a photo in the middle. (there may be more than one next/previous photo returned).
""" """
if not isinstance(photo, Photo): if not isinstance(photo, Photo):
photo = Photo(self._client, {"id": photo}) photo = Photo(self._client, {"id": photo})

View file

@ -74,14 +74,21 @@ class Photo(OpenPhotoObject):
raise NotImplementedError() raise NotImplementedError()
def next_previous(self, **kwds): def next_previous(self, **kwds):
""" Returns a dict containing the next and previous photo objects """ """
Returns a dict containing the next and previous photo lists
(there may be more than one next/previous photo returned).
"""
result = self._openphoto.get("/photo/%s/nextprevious.json" % self.id, result = self._openphoto.get("/photo/%s/nextprevious.json" % self.id,
**kwds)["result"] **kwds)["result"]
value = {} value = {}
if "next" in result: if "next" in result:
value["next"] = Photo(self._openphoto, result["next"]) value["next"] = []
for photo in result["next"]:
value["next"].append(Photo(self._openphoto, photo))
if "previous" in result: if "previous" in result:
value["previous"] = Photo(self._openphoto, result["previous"]) value["previous"] = []
for photo in result["previous"]:
value["previous"].append(Photo(self._openphoto, photo))
return value return value
def transform(self, **kwds): def transform(self, **kwds):

View file

@ -123,13 +123,13 @@ class TestPhotos(test_base.TestBase):
def test_next_previous(self): def test_next_previous(self):
""" Test the next/previous links of the middle photo """ """ Test the next/previous links of the middle photo """
next_prev = self.client.photo.next_previous(self.photos[1]) next_prev = self.client.photo.next_previous(self.photos[1])
self.assertEqual(next_prev["previous"].id, self.photos[0].id) self.assertEqual(next_prev["previous"][0].id, self.photos[0].id)
self.assertEqual(next_prev["next"].id, self.photos[2].id) self.assertEqual(next_prev["next"][0].id, self.photos[2].id)
# Do the same using the Photo object directly # Do the same using the Photo object directly
next_prev = self.photos[1].next_previous() next_prev = self.photos[1].next_previous()
self.assertEqual(next_prev["previous"].id, self.photos[0].id) self.assertEqual(next_prev["previous"][0].id, self.photos[0].id)
self.assertEqual(next_prev["next"].id, self.photos[2].id) self.assertEqual(next_prev["next"][0].id, self.photos[2].id)
def test_replace(self): def test_replace(self):
""" If photo.replace gets implemented, write a test! """ """ If photo.replace gets implemented, write a test! """