diff --git a/tests/functional/test_activities.py b/tests/functional/test_activities.py index 854e70a..43e3af4 100644 --- a/tests/functional/test_activities.py +++ b/tests/functional/test_activities.py @@ -30,9 +30,9 @@ class TestActivities(test_base.TestBase): for photo in photos: photo.update(tags=self.TEST_TAG) - def test_list_filter(self): + def test_list_option(self): """ - Check that the activity list filter parameter works correctly + Check that the activity list options parameter works correctly """ self._delete_all() self._create_test_photos(tag=False) @@ -42,8 +42,8 @@ class TestActivities(test_base.TestBase): photos[0].update(tags=photos[0].tags) # Check that the activities can be filtered - upload_activities = self.client.activities.list(filters={"type": "photo-upload"}) - update_activities = self.client.activities.list(filters={"type": "photo-update"}) + upload_activities = self.client.activities.list(options={"type": "photo-upload"}) + update_activities = self.client.activities.list(options={"type": "photo-update"}) self.assertEqual(len(upload_activities), len(photos)) self.assertEqual(len(update_activities), 1) diff --git a/tests/functional/test_photos.py b/tests/functional/test_photos.py index edb4978..d00c689 100644 --- a/tests/functional/test_photos.py +++ b/tests/functional/test_photos.py @@ -12,21 +12,21 @@ from tests.functional import test_base class TestPhotos(test_base.TestBase): testcase_name = "photo API" - def test_list_filter(self): + def test_list_option(self): """ - Check that the photo list filter parameter works correctly + Check that the photo list options parameter works correctly """ - filter_tag = "Filter" + option_tag = "Filter" # Assign a photo with a new tag - self.photos[0].update(tagsAdd=filter_tag) + self.photos[0].update(tagsAdd=option_tag) # Check that the photos can be filtered - photos = self.client.photos.list(filters={"tags": filter_tag}) + photos = self.client.photos.list(options={"tags": option_tag}) self.assertEqual(len(photos), 1) self.assertEqual(photos[0].id, self.photos[0].id) # Put the environment back the way we found it - photos[0].update(tagsRemove=filter_tag) + photos[0].update(tagsRemove=option_tag) # Photo share endpoint is currently not implemented @unittest.expectedFailure diff --git a/tests/unit/test_activities.py b/tests/unit/test_activities.py index df0a7ba..9d209ae 100644 --- a/tests/unit/test_activities.py +++ b/tests/unit/test_activities.py @@ -69,10 +69,10 @@ class TestActivitiesList(TestActivities): self.assertEqual(result, []) @mock.patch.object(trovebox.Trovebox, 'get') - def test_filters(self, mock_get): - """Check that the activity list filters are applied properly""" + def test_options(self, mock_get): + """Check that the activity list optionss are applied properly""" mock_get.return_value = self._return_value(self.test_activities_dict) - self.client.activities.list(filters={"foo": "bar", + self.client.activities.list(options={"foo": "bar", "test1": "test2"}, foo="bar") # Dict element can be any order diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index f7b42ae..2a739fe 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -56,10 +56,10 @@ class TestPhotosList(TestPhotos): self.assertEqual(result, []) @mock.patch.object(trovebox.Trovebox, 'get') - def test_filters(self, mock_get): - """Check that the activity list filters are applied properly""" + def test_options(self, mock_get): + """Check that the activity list options are applied properly""" mock_get.return_value = self._return_value(self.test_photos_dict) - self.client.photos.list(filters={"foo": "bar", + self.client.photos.list(options={"foo": "bar", "test1": "test2"}, foo="bar") # Dict element can be any order @@ -71,7 +71,7 @@ class TestPhotosList(TestPhotos): class TestPhotosShare(TestPhotos): @mock.patch.object(trovebox.Trovebox, 'post') def test_photos_share(self, mock_post): - self.client.photos.share(filters={"foo": "bar", + self.client.photos.share(options={"foo": "bar", "test1": "test2"}, foo="bar") # Dict element can be any order @@ -362,16 +362,30 @@ class TestPhotoView(TestPhotos): """Check that a photo can be viewed""" mock_get.return_value = self._return_value(self.test_photos_dict[1]) result = self.client.photo.view(self.test_photos[0], + options={"foo": "bar", + "test1": "test2"}, returnSizes="20x20") - mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20") + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/foo-bar/test1-test2/view.json",), + ("/photo/1a/test1-test2/foo-bar/view.json",)]) + self.assertEqual(mock_get.call_args[1], {"returnSizes": "20x20"}) self.assertEqual(result.get_fields(), self.test_photos_dict[1]) @mock.patch.object(trovebox.Trovebox, 'get') def test_photo_view_id(self, mock_get): """Check that a photo can be viewed using its ID""" mock_get.return_value = self._return_value(self.test_photos_dict[1]) - result = self.client.photo.view("1a", returnSizes="20x20") - mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20") + result = self.client.photo.view("1a", + options={"foo": "bar", + "test1": "test2"}, + returnSizes="20x20") + + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/foo-bar/test1-test2/view.json",), + ("/photo/1a/test1-test2/foo-bar/view.json",)]) + self.assertEqual(mock_get.call_args[1], {"returnSizes": "20x20"}) self.assertEqual(result.get_fields(), self.test_photos_dict[1]) @mock.patch.object(trovebox.Trovebox, 'get') @@ -382,8 +396,14 @@ class TestPhotoView(TestPhotos): """ mock_get.return_value = self._return_value(self.test_photos_dict[1]) photo = self.test_photos[0] - photo.view(returnSizes="20x20") - mock_get.assert_called_with("/photo/1a/view.json", returnSizes="20x20") + photo.view(returnSizes="20x20", options={"foo": "bar", + "test1": "test2"}) + + # Dict elemet can be in any order + self.assertIn(mock_get.call_args[0], + [("/photo/1a/foo-bar/test1-test2/view.json",), + ("/photo/1a/test1-test2/foo-bar/view.json",)]) + self.assertEqual(mock_get.call_args[1], {"returnSizes": "20x20"}) self.assertEqual(photo.get_fields(), self.test_photos_dict[1]) class TestPhotoUpload(TestPhotos): diff --git a/trovebox/api/api_activity.py b/trovebox/api/api_activity.py index cd8e308..bccbd84 100644 --- a/trovebox/api/api_activity.py +++ b/trovebox/api/api_activity.py @@ -7,16 +7,16 @@ from .api_base import ApiBase class ApiActivities(ApiBase): """ Definitions of /activities/ API endpoints """ - def list(self, filters=None, **kwds): + def list(self, options=None, **kwds): """ - Endpoint: /activities/[]/list.json + Endpoint: /activities/[]/list.json Returns a list of Activity objects. - The filters parameter can be used to narrow down the activities. - Eg: filters={"type": "photo-upload"} + The options parameter can be used to narrow down the activities. + Eg: options={"type": "photo-upload"} """ - filter_string = self._build_filter_string(filters) - activities = self._client.get("/activities/%slist.json" % filter_string, + option_string = self._build_option_string(options) + activities = self._client.get("/activities/%slist.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 15f0f4b..c79ab9f 100644 --- a/trovebox/api/api_base.py +++ b/trovebox/api/api_base.py @@ -8,16 +8,16 @@ class ApiBase(object): self._client = client @staticmethod - def _build_filter_string(filters): + def _build_option_string(options): """ - :param filters: dictionary containing the filters - :returns: filter_string formatted for an API endpoint + :param options: dictionary containing the options + :returns: option_string formatted for an API endpoint """ - filter_string = "" - if filters is not None: - for filt in filters: - filter_string += "%s-%s/" % (filt, filters[filt]) - return filter_string + option_string = "" + if options is not None: + for key in options: + option_string += "%s-%s/" % (key, options[key]) + return option_string @staticmethod def _extract_id(obj): diff --git a/trovebox/api/api_photo.py b/trovebox/api/api_photo.py index c9c2c73..f9a86bb 100644 --- a/trovebox/api/api_photo.py +++ b/trovebox/api/api_photo.py @@ -8,28 +8,28 @@ from .api_base import ApiBase class ApiPhotos(ApiBase): """ Definitions of /photos/ API endpoints """ - def list(self, filters=None, **kwds): + def list(self, options=None, **kwds): """ - Endpoint: /photos/[]/list.json + Endpoint: /photos/[]/list.json Returns a list of Photo objects. - The filters parameter can be used to narrow down the list. - Eg: filters={"album": } + The options parameter can be used to narrow down the list. + Eg: options={"album": } """ - filter_string = self._build_filter_string(filters) - photos = self._client.get("/photos/%slist.json" % filter_string, + option_string = self._build_option_string(options) + photos = self._client.get("/photos/%slist.json" % option_string, **kwds)["result"] photos = self._result_to_list(photos) return [Photo(self._client, photo) for photo in photos] - def share(self, filters=None, **kwds): + def share(self, options=None, **kwds): """ - Endpoint: /photos/[/share.json + Endpoint: /photos/[/share.json Not currently implemented. """ - filter_string = self._build_filter_string(filters) - return self._client.post("/photos/%sshare.json" % filter_string, + option_string = self._build_option_string(options) + return self._client.post("/photos/%sshare.json" % option_string, **kwds)["result"] def delete(self, photos, **kwds): @@ -136,18 +136,20 @@ class ApiPhoto(ApiBase): **kwds)["result"] return Photo(self._client, result) - # TODO: Add options - def view(self, photo, **kwds): + 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, by using the "returnSizes" parameter. Returns the requested photo object. + The options parameter can be used to pass in additional options. + Eg: options={"token": } """ - result = self._client.get("/photo/%s/view.json" % - self._extract_id(photo), + option_string = self._build_option_string(options) + result = self._client.get("/photo/%s/%sview.json" % + (self._extract_id(photo), option_string), **kwds)["result"] return Photo(self._client, result)