Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apiv1 fixes #34

Merged
merged 4 commits into from
May 17, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions openphoto/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down
12 changes: 12 additions & 0 deletions tests/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions tests/api_versions/test_v1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from tests import test_albums, test_photos, test_tags

class TestAlbumsV1(test_albums.TestAlbums):
Expand Down
6 changes: 5 additions & 1 deletion tests/api_versions/test_v2.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 16 additions & 2 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down