diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index 0686a88..8eb561a 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -81,8 +81,8 @@ class ApiPhoto: def next_previous(self, photo, **kwds): """ - Returns a dict containing the next and previous photo objects, - given a photo in the middle. + Returns a dict containing the next and previous photo lists + (there may be more than one next/previous photo returned). """ if not isinstance(photo, Photo): photo = Photo(self._client, {"id": photo}) diff --git a/openphoto/objects.py b/openphoto/objects.py index a2328bf..965df9a 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -74,14 +74,21 @@ class Photo(OpenPhotoObject): raise NotImplementedError() 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, **kwds)["result"] value = {} 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: - value["previous"] = Photo(self._openphoto, result["previous"]) + value["previous"] = [] + for photo in result["previous"]: + value["previous"].append(Photo(self._openphoto, photo)) return value def transform(self, **kwds): diff --git a/tests/test_photos.py b/tests/test_photos.py index 68e9cac..313f2ca 100644 --- a/tests/test_photos.py +++ b/tests/test_photos.py @@ -123,13 +123,13 @@ class TestPhotos(test_base.TestBase): def test_next_previous(self): """ Test the next/previous links of the middle photo """ next_prev = self.client.photo.next_previous(self.photos[1]) - self.assertEqual(next_prev["previous"].id, self.photos[0].id) - self.assertEqual(next_prev["next"].id, self.photos[2].id) + self.assertEqual(next_prev["previous"][0].id, self.photos[0].id) + self.assertEqual(next_prev["next"][0].id, self.photos[2].id) # Do the same using the Photo object directly next_prev = self.photos[1].next_previous() - self.assertEqual(next_prev["previous"].id, self.photos[0].id) - self.assertEqual(next_prev["next"].id, self.photos[2].id) + self.assertEqual(next_prev["previous"][0].id, self.photos[0].id) + self.assertEqual(next_prev["next"][0].id, self.photos[2].id) def test_replace(self): """ If photo.replace gets implemented, write a test! """