Skip to content

Commit a2d103e

Browse files
committed
Merge pull request #34 from sneakypete81/apiv1_fixes
Apiv1 fixes
2 parents 6572ca7 + c76ad3f commit a2d103e

7 files changed

Lines changed: 48 additions & 4 deletions

File tree

openphoto/objects.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def transform(self, **kwds):
114114
"""
115115
new_dict = self._openphoto.post("/photo/%s/transform.json" % self.id,
116116
**kwds)["result"]
117+
118+
# APIv1 doesn't return the transformed photo (frontend issue #955)
119+
if isinstance(new_dict, bool):
120+
new_dict = self._openphoto.get("/photo/%s/view.json" % self.id)["result"]
121+
117122
self._replace_fields(new_dict)
118123

119124
class Tag(OpenPhotoObject):
@@ -173,6 +178,11 @@ def update(self, **kwds):
173178
""" Update this album with the specified parameters """
174179
new_dict = self._openphoto.post("/album/%s/update.json" % self.id,
175180
**kwds)["result"]
181+
182+
# APIv1 doesn't return the updated album (frontend issue #937)
183+
if isinstance(new_dict, bool):
184+
new_dict = self._openphoto.get("/album/%s/view.json" % self.id)["result"]
185+
176186
self._replace_fields(new_dict)
177187
self._update_fields_with_objects()
178188

tests/README.markdown

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ Ensure there are:
6565
**TearDownClass:**
6666

6767
Remove all photos, tags and albums
68+
69+
### Testing old servers
70+
71+
By default, all currently supported API versions will be tested.
72+
It's useful to test servers that only support older API versions.
73+
To restrict the testing to a specific maximum API version, use the
74+
``OPENPHOTO_TEST_SERVER_API`` environment variable.
75+
76+
For example, to restrict testing to APIv1 and APIv2:
77+
78+
export OPENPHOTO_TEST_SERVER_API=2
79+

tests/api_versions/test_v1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import unittest
12
from tests import test_albums, test_photos, test_tags
23

34
class TestAlbumsV1(test_albums.TestAlbums):

tests/api_versions/test_v2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from tests import test_albums, test_photos, test_tags
1+
import unittest
2+
from tests import test_base, test_albums, test_photos, test_tags
23

4+
@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions")
35
class TestAlbumsV2(test_albums.TestAlbums):
46
api_version = 2
57

8+
@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions")
69
class TestPhotosV2(test_photos.TestPhotos):
710
api_version = 2
811

12+
@unittest.skipIf(test_base.get_test_server_api() < 2, "Don't test future API versions")
913
class TestTagsV2(test_tags.TestTags):
1014
api_version = 2

tests/test_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import logging
44
import openphoto
55

6+
def get_test_server_api():
7+
return int(os.getenv("OPENPHOTO_TEST_SERVER_API", openphoto.LATEST_API_VERSION))
8+
69
class TestBase(unittest.TestCase):
710
TEST_TITLE = "Test Image - delete me!"
811
TEST_TAG = "test_tag"

tests/test_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_api_version_zero(self):
2020

2121
def test_specified_api_version(self):
2222
# For all API versions >0, we get a generic hello world message
23-
for api_version in range(1, openphoto.LATEST_API_VERSION + 1):
23+
for api_version in range(1, test_base.get_test_server_api() + 1):
2424
client = openphoto.OpenPhoto(config_file=self.config_file,
2525
api_version=api_version)
2626
result = client.get("hello.json")

tests/test_tags.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
import openphoto
33
import test_base
44

5+
@unittest.skipIf(test_base.get_test_server_api() == 1,
6+
"The tag API didn't work at v1 - see frontend issue #927")
57
class TestTags(test_base.TestBase):
68
testcase_name = "tag API"
79

810
def test_create_delete(self, tag_id="create_tag"):
9-
""" Create a tag then delete it """
11+
"""
12+
Create a tag then delete it.
13+
This test is a little contrived, since the tag create/delete
14+
endpoints are only intended for internal use.
15+
"""
1016
# Create a tag
1117
self.assertTrue(self.client.tag.create(tag_id))
1218
# 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"):
2127
self.assertTrue(self.client.tag.delete(tag_id))
2228
# Check that the tag is now gone
2329
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
30+
# Also remove the tag from the photo
31+
self.photos[0].update(tagsRemove=tag_id)
2432

25-
# Create then delete using the Tag object directly
33+
# Create the tag again
2634
self.photos[0].update(tagsAdd=tag_id)
35+
self.assertIn(tag_id, [t.id for t in self.client.tags.list()])
36+
37+
# Delete using the tag object directly
2738
tag = [t for t in self.client.tags.list() if t.id == tag_id][0]
2839
self.assertTrue(tag.delete())
40+
2941
# Check that the tag is now gone
3042
self.assertNotIn(tag_id, [t.id for t in self.client.tags.list()])
43+
# Also remove the tag from the photo
44+
self.photos[0].update(tagsRemove=tag_id)
3145

3246
# TODO: Un-skip and update this tests once there are tag fields that can be updated.
3347
# The owner field cannot be updated.

0 commit comments

Comments
 (0)