diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index 2a739fe..280e60d 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -473,9 +473,14 @@ class TestPhotoNextPrevious(TestPhotos): {"next": [self.test_photos_dict[0]], "previous": [self.test_photos_dict[1]]}) result = self.client.photo.next_previous(self.test_photos[0], + options={"foo": "bar", + "test1": "test2"}, foo="bar") - mock_get.assert_called_with("/photo/1a/nextprevious.json", - foo="bar") + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/nextprevious/foo-bar/test1-test2.json",), + ("/photo/1a/nextprevious/test1-test2/foo-bar.json",)]) + self.assertEqual(mock_get.call_args[1], {"foo": "bar"}) self.assertEqual(result["next"][0].get_fields(), self.test_photos_dict[0]) self.assertEqual(result["previous"][0].get_fields(), @@ -490,9 +495,15 @@ class TestPhotoNextPrevious(TestPhotos): mock_get.return_value = self._return_value( {"next": [self.test_photos_dict[0]], "previous": [self.test_photos_dict[1]]}) - result = self.client.photo.next_previous("1a", foo="bar") - mock_get.assert_called_with("/photo/1a/nextprevious.json", - foo="bar") + result = self.client.photo.next_previous("1a", + options={"foo": "bar", + "test1": "test2"}, + foo="bar") + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/nextprevious/foo-bar/test1-test2.json",), + ("/photo/1a/nextprevious/test1-test2/foo-bar.json",)]) + self.assertEqual(mock_get.call_args[1], {"foo": "bar"}) self.assertEqual(result["next"][0].get_fields(), self.test_photos_dict[0]) self.assertEqual(result["previous"][0].get_fields(), @@ -507,9 +518,14 @@ class TestPhotoNextPrevious(TestPhotos): mock_get.return_value = self._return_value( {"next": [self.test_photos_dict[0]], "previous": [self.test_photos_dict[1]]}) - result = self.test_photos[0].next_previous(foo="bar") - mock_get.assert_called_with("/photo/1a/nextprevious.json", - foo="bar") + result = self.test_photos[0].next_previous(options={"foo": "bar", + "test1": "test2"}, + foo="bar") + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/nextprevious/foo-bar/test1-test2.json",), + ("/photo/1a/nextprevious/test1-test2/foo-bar.json",)]) + self.assertEqual(mock_get.call_args[1], {"foo": "bar"}) self.assertEqual(result["next"][0].get_fields(), self.test_photos_dict[0]) self.assertEqual(result["previous"][0].get_fields(), diff --git a/trovebox/api/api_activity.py b/trovebox/api/api_activity.py index bccbd84..2e17c88 100644 --- a/trovebox/api/api_activity.py +++ b/trovebox/api/api_activity.py @@ -9,14 +9,14 @@ class ApiActivities(ApiBase): """ Definitions of /activities/ API endpoints """ def list(self, options=None, **kwds): """ - Endpoint: /activities/[]/list.json + Endpoint: /activities[/]/list.json Returns a list of Activity objects. The options parameter can be used to narrow down the activities. Eg: options={"type": "photo-upload"} """ option_string = self._build_option_string(options) - activities = self._client.get("/activities/%slist.json" % option_string, + activities = self._client.get("/activities%s/list.json" % option_string, **kwds)["result"] activities = self._result_to_list(activities) return [Activity(self._client, activity) for activity in activities] diff --git a/trovebox/api/api_base.py b/trovebox/api/api_base.py index c79ab9f..5aaf16c 100644 --- a/trovebox/api/api_base.py +++ b/trovebox/api/api_base.py @@ -16,7 +16,7 @@ class ApiBase(object): option_string = "" if options is not None: for key in options: - option_string += "%s-%s/" % (key, options[key]) + option_string += "/%s-%s" % (key, options[key]) return option_string @staticmethod diff --git a/trovebox/api/api_photo.py b/trovebox/api/api_photo.py index f9a86bb..caa67e5 100644 --- a/trovebox/api/api_photo.py +++ b/trovebox/api/api_photo.py @@ -10,26 +10,26 @@ class ApiPhotos(ApiBase): """ Definitions of /photos/ API endpoints """ def list(self, options=None, **kwds): """ - Endpoint: /photos/[]/list.json + Endpoint: /photos[/]/list.json Returns a list of Photo objects. The options parameter can be used to narrow down the list. Eg: options={"album": } """ option_string = self._build_option_string(options) - photos = self._client.get("/photos/%slist.json" % option_string, + photos = self._client.get("/photos%s/list.json" % option_string, **kwds)["result"] photos = self._result_to_list(photos) return [Photo(self._client, photo) for photo in photos] def share(self, options=None, **kwds): """ - Endpoint: /photos/[/share.json + Endpoint: /photos[//share.json Not currently implemented. """ option_string = self._build_option_string(options) - return self._client.post("/photos/%sshare.json" % option_string, + return self._client.post("/photos%s/share.json" % option_string, **kwds)["result"] def delete(self, photos, **kwds): @@ -138,7 +138,7 @@ class ApiPhoto(ApiBase): def view(self, photo, options=None, **kwds): """ - Endpoint: /photo//[]/view.json + Endpoint: /photo/[/]/view.json Requests all properties of a photo. Can be used to obtain URLs for the photo at a particular size, @@ -148,7 +148,7 @@ class ApiPhoto(ApiBase): Eg: options={"token": } """ option_string = self._build_option_string(options) - result = self._client.get("/photo/%s/%sview.json" % + result = self._client.get("/photo/%s%s/view.json" % (self._extract_id(photo), option_string), **kwds)["result"] return Photo(self._client, result) @@ -192,15 +192,18 @@ class ApiPhoto(ApiBase): raise NotImplementedError() # TODO: Add options - def next_previous(self, photo, **kwds): + def next_previous(self, photo, options=None, **kwds): """ - Endpoint: /photo//nextprevious.json + Endpoint: /photo//nextprevious[/].json Returns a dict containing the next and previous photo lists (there may be more than one next/previous photo returned). + The options parameter can be used to narrow down the photos + Eg: options={"album": } """ - result = self._client.get("/photo/%s/nextprevious.json" % - self._extract_id(photo), + option_string = self._build_option_string(options) + result = self._client.get("/photo/%s/nextprevious%s.json" % + (self._extract_id(photo), option_string), **kwds)["result"] value = {} if "next" in result: diff --git a/trovebox/objects/photo.py b/trovebox/objects/photo.py index e4a2c0d..af301a4 100644 --- a/trovebox/objects/photo.py +++ b/trovebox/objects/photo.py @@ -69,7 +69,7 @@ class Photo(TroveboxObject): def view(self, options=None, **kwds): """ - Endpoint: /photo//view.json + Endpoint: /photo/[/]/view.json Requests all properties of this photo. Can be used to obtain URLs for the photo at a particular size, @@ -85,15 +85,14 @@ class Photo(TroveboxObject): """ Not implemented yet """ raise NotImplementedError() - # TODO: Add options - def next_previous(self, **kwds): + def next_previous(self, options=None, **kwds): """ - Endpoint: /photo//nextprevious.json + Endpoint: /photo//nextprevious[/].json Returns a dict containing the next and previous photo lists (there may be more than one next/previous photo returned). """ - return self._client.photo.next_previous(self, **kwds) + return self._client.photo.next_previous(self, options, **kwds) def transform(self, **kwds): """