diff --git a/openphoto/objects.py b/openphoto/objects.py index 589bbec..155c711 100644 --- a/openphoto/objects.py +++ b/openphoto/objects.py @@ -114,6 +114,11 @@ def transform(self, **kwds): """ new_dict = self._openphoto.post("/photo/%s/transform.json" % self.id, **kwds)["result"] + + # APIv1 doesn't return the transformed photo (frontend issue #955) + if isinstance(new_dict, bool): + new_dict = self._openphoto.get("/photo/%s/view.json" % self.id)["result"] + self._replace_fields(new_dict) class Tag(OpenPhotoObject): @@ -173,6 +178,11 @@ def update(self, **kwds): """ Update this album with the specified parameters """ new_dict = self._openphoto.post("/album/%s/update.json" % self.id, **kwds)["result"] + + # APIv1 doesn't return the updated album (frontend issue #937) + if isinstance(new_dict, bool): + new_dict = self._openphoto.get("/album/%s/view.json" % self.id)["result"] + self._replace_fields(new_dict) self._update_fields_with_objects() diff --git a/tests/README.markdown b/tests/README.markdown index 26813ee..b8f8cd7 100644 --- a/tests/README.markdown +++ b/tests/README.markdown @@ -65,3 +65,15 @@ Ensure there are: **TearDownClass:** Remove all photos, tags and albums + +### Testing old servers + +By default, all currently supported API versions will be tested. +It's useful to test servers that only support older API versions. +To restrict the testing to a specific maximum API version, use the +``OPENPHOTO_TEST_SERVER_API`` environment variable. + +For example, to restrict testing to APIv1 and APIv2: + + export OPENPHOTO_TEST_SERVER_API=2 + diff --git a/tests/api_versions/test_v1.py b/tests/api_versions/test_v1.py index 92baabb..2f169bd 100644 --- a/tests/api_versions/test_v1.py +++ b/tests/api_versions/test_v1.py @@ -1,3 +1,4 @@ +import unittest from tests import test_albums, test_photos, test_tags class TestAlbumsV1(test_albums.TestAlbums): diff --git a/tests/api_versions/test_v2.py b/tests/api_versions/test_v2.py index a6cfa4e..447946d 100644 --- a/tests/api_versions/test_v2.py +++ b/tests/api_versions/test_v2.py @@ -1,10 +1,14 @@ -from tests import test_albums, test_photos, test_tags +import unittest +from tests import test_base, test_albums, test_photos, test_tags +@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestAlbumsV2(test_albums.TestAlbums): api_version = 2 +@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestPhotosV2(test_photos.TestPhotos): api_version = 2 +@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions") class TestTagsV2(test_tags.TestTags): api_version = 2 diff --git a/tests/test_base.py b/tests/test_base.py index 94b8d4a..8d793b9 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -3,6 +3,9 @@ import logging import openphoto +def get_test_server_api(): + return int(os.getenv("OPENPHOTO_TEST_SERVER_API", openphoto.LATEST_API_VERSION)) + class TestBase(unittest.TestCase): TEST_TITLE = "Test Image - delete me!" TEST_TAG = "test_tag" diff --git a/tests/test_framework.py b/tests/test_framework.py index b28fc23..5eb9e8b 100644 --- a/tests/test_framework.py +++ b/tests/test_framework.py @@ -20,7 +20,7 @@ def test_api_version_zero(self): def test_specified_api_version(self): # For all API versions >0, we get a generic hello world message - for api_version in range(1, openphoto.LATEST_API_VERSION + 1): + for api_version in range(1, test_base.get_test_server_api() + 1): client = openphoto.OpenPhoto(config_file=self.config_file, api_version=api_version) result = client.get("hello.json") diff --git a/tests/test_tags.py b/tests/test_tags.py index 17b0eca..351c320 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -2,11 +2,17 @@ import openphoto import test_base +@unittest.skipIf(test_base.get_test_server_api() == 1, + "The tag API didn't work at v1 - see frontend issue #927") class TestTags(test_base.TestBase): testcase_name = "tag API" def test_create_delete(self, tag_id="create_tag"): - """ Create a tag then delete it """ + """ + Create a tag then delete it. + This test is a little contrived, since the tag create/delete + endpoints are only intended for internal use. + """ # Create a tag self.assertTrue(self.client.tag.create(tag_id)) # Check that the tag doesn't exist (It has no photos, so it's invisible) @@ -21,13 +27,21 @@ def test_create_delete(self, tag_id="create_tag"): self.assertTrue(self.client.tag.delete(tag_id)) # Check that the tag is now gone self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()]) + # Also remove the tag from the photo + self.photos[0].update(tagsRemove=tag_id) - # Create then delete using the Tag object directly + # Create the tag again self.photos[0].update(tagsAdd=tag_id) + self.assertIn(tag_id, [t.id for t in self.client.tags.list()]) + + # Delete using the tag object directly tag = [t for t in self.client.tags.list() if t.id == tag_id][0] self.assertTrue(tag.delete()) + # Check that the tag is now gone self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()]) + # Also remove the tag from the photo + self.photos[0].update(tagsRemove=tag_id) # TODO: Un-skip and update this tests once there are tag fields that can be updated. # The owner field cannot be updated.