photos.update/update now also accept a list of Photo objects

This commit is contained in:
sneakypete81 2013-06-30 17:30:25 +01:00
parent 280521cf4a
commit 3f1757d0aa
2 changed files with 17 additions and 6 deletions

View file

@ -4,6 +4,19 @@ from openphoto.errors import OpenPhotoError
import openphoto.openphoto_http import openphoto.openphoto_http
from openphoto.objects import Photo from openphoto.objects import Photo
def extract_ids(photos):
"""
Given a list of objects, extract the photo id for each Photo
object.
"""
ids = []
for photo in photos:
if isinstance(photo, Photo):
ids.append(photo.id)
else:
ids.append(photo)
return ids
class ApiPhotos: class ApiPhotos:
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
@ -20,7 +33,8 @@ class ApiPhotos:
Returns True if successful. Returns True if successful.
Raises OpenPhotoError if not. Raises OpenPhotoError if not.
""" """
if not self._client.post("/photos/update.json", ids=photos, ids = extract_ids(photos)
if not self._client.post("/photos/update.json", ids=ids,
**kwds)["result"]: **kwds)["result"]:
raise OpenPhotoError("Update response returned False") raise OpenPhotoError("Update response returned False")
return True return True
@ -31,7 +45,8 @@ class ApiPhotos:
Returns True if successful. Returns True if successful.
Raises OpenPhotoError if not. Raises OpenPhotoError if not.
""" """
if not self._client.post("/photos/delete.json", ids=photos, ids = extract_ids(photos)
if not self._client.post("/photos/delete.json", ids=ids,
**kwds)["result"]: **kwds)["result"]:
raise OpenPhotoError("Delete response returned False") raise OpenPhotoError("Delete response returned False")
return True return True

View file

@ -40,8 +40,6 @@ class TestPhotosList(TestPhotos):
self.assertEqual(result[1].tags, ["tag3", "tag4"]) self.assertEqual(result[1].tags, ["tag3", "tag4"])
class TestPhotosUpdate(TestPhotos): class TestPhotosUpdate(TestPhotos):
# TODO: photos.update should accept a list of Photo objects
@unittest.expectedFailure
@mock.patch.object(openphoto.OpenPhoto, 'post') @mock.patch.object(openphoto.OpenPhoto, 'post')
def test_photos_update(self, mock_post): def test_photos_update(self, mock_post):
"""Check that multiple photos can be updated""" """Check that multiple photos can be updated"""
@ -71,8 +69,6 @@ class TestPhotosUpdate(TestPhotos):
self.client.photos.update(self.test_photos, title="Test") self.client.photos.update(self.test_photos, title="Test")
class TestPhotosDelete(TestPhotos): class TestPhotosDelete(TestPhotos):
# TODO: photos.delete should accept a list of Photo objects
@unittest.expectedFailure
@mock.patch.object(openphoto.OpenPhoto, 'post') @mock.patch.object(openphoto.OpenPhoto, 'post')
def test_photos_delete(self, mock_post): def test_photos_delete(self, mock_post):
"""Check that multiple photos can be deleted""" """Check that multiple photos can be deleted"""