From 3f1757d0aa8b3d1fc61d20596218625560ffd24d Mon Sep 17 00:00:00 2001 From: sneakypete81 Date: Sun, 30 Jun 2013 17:30:25 +0100 Subject: [PATCH] photos.update/update now also accept a list of Photo objects --- openphoto/api_photo.py | 19 +++++++++++++++++-- tests/unit/test_photos.py | 4 ---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/openphoto/api_photo.py b/openphoto/api_photo.py index cfa2c45..c5052ef 100644 --- a/openphoto/api_photo.py +++ b/openphoto/api_photo.py @@ -4,6 +4,19 @@ from openphoto.errors import OpenPhotoError import openphoto.openphoto_http 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: def __init__(self, client): self._client = client @@ -20,7 +33,8 @@ class ApiPhotos: Returns True if successful. 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"]: raise OpenPhotoError("Update response returned False") return True @@ -31,7 +45,8 @@ class ApiPhotos: Returns True if successful. 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"]: raise OpenPhotoError("Delete response returned False") return True diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index bf783fe..6a53677 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -40,8 +40,6 @@ class TestPhotosList(TestPhotos): self.assertEqual(result[1].tags, ["tag3", "tag4"]) class TestPhotosUpdate(TestPhotos): - # TODO: photos.update should accept a list of Photo objects - @unittest.expectedFailure @mock.patch.object(openphoto.OpenPhoto, 'post') def test_photos_update(self, mock_post): """Check that multiple photos can be updated""" @@ -71,8 +69,6 @@ class TestPhotosUpdate(TestPhotos): self.client.photos.update(self.test_photos, title="Test") class TestPhotosDelete(TestPhotos): - # TODO: photos.delete should accept a list of Photo objects - @unittest.expectedFailure @mock.patch.object(openphoto.OpenPhoto, 'post') def test_photos_delete(self, mock_post): """Check that multiple photos can be deleted"""