diff --git a/tests/functional/test_photos.py b/tests/functional/test_photos.py index 92b6cd5..2ac225a 100644 --- a/tests/functional/test_photos.py +++ b/tests/functional/test_photos.py @@ -74,6 +74,22 @@ class TestPhotos(test_base.TestBase): self._delete_all() self._create_test_photos() + def test_delete_source(self): + """ Test that photo source files can be deleted """ + # Upload a new (duplicate) photo + photo = self.client.photo.upload("tests/data/test_photo1.jpg", + allowDuplicate=True) + # Check that the photo can be downloaded + self.client.get("photo/%s/download" % photo.id, process_response=False) + + # Delete the source and check that the source file no longer exists + photo.delete_source() + with self.assertRaises(trovebox.TroveboxError): + self.client.get("photo/%s/download" % photo.id, process_response=False) + + # Put the environment back the way we found it + photo.delete() + def test_upload_duplicate(self): """ Ensure that duplicate photos are rejected """ # Attempt to upload a duplicate diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index 4107c8e..ecc1604 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -149,6 +149,35 @@ class TestPhotoDelete(TestPhotos): self.assertEqual(photo.get_fields(), {}) self.assertEqual(photo.id, None) +class TestPhotoDeleteSource(TestPhotos): + @mock.patch.object(trovebox.Trovebox, 'post') + def test_photo_delete_source(self, mock_post): + """Check that photo source files can be deleted""" + mock_post.return_value = self._return_value(True) + result = self.client.photo.delete_source(self.test_photos[0], foo="bar") + mock_post.assert_called_with("/photo/1a/source/delete.json", foo="bar") + self.assertEqual(result, True) + + @mock.patch.object(trovebox.Trovebox, 'post') + def test_photo_delete_source_id(self, mock_post): + """Check that photo source files can be deleted using its ID""" + mock_post.return_value = self._return_value(True) + result = self.client.photo.delete_source("1a", foo="bar") + mock_post.assert_called_with("/photo/1a/source/delete.json", foo="bar") + self.assertEqual(result, True) + + @mock.patch.object(trovebox.Trovebox, 'post') + def test_photo_object_delete_source(self, mock_post): + """ + Check that photo source files can be deleted when using + the photo object directly + """ + mock_post.return_value = self._return_value(True) + photo = self.test_photos[0] + result = photo.delete_source(foo="bar") + mock_post.assert_called_with("/photo/1a/source/delete.json", foo="bar") + self.assertEqual(result, True) + class TestPhotoReplace(TestPhotos): @mock.patch.object(trovebox.Trovebox, 'post') def test_photo_replace(self, _): diff --git a/trovebox/api/api_photo.py b/trovebox/api/api_photo.py index 334d37a..7a3d42a 100644 --- a/trovebox/api/api_photo.py +++ b/trovebox/api/api_photo.py @@ -71,6 +71,18 @@ class ApiPhoto(ApiBase): self._extract_id(photo), **kwds)["result"] + def delete_source(self, photo, **kwds): + """ + Endpoint: /photo//source/delete.json + + Delete the source files of a photo. + Returns True if successful. + Raises a TroveboxError if not. + """ + return self._client.post("/photo/%s/source/delete.json" % + self._extract_id(photo), + **kwds)["result"] + def replace(self, photo, photo_file, **kwds): """ Not yet implemented """ raise NotImplementedError() diff --git a/trovebox/objects/photo.py b/trovebox/objects/photo.py index 28865c5..2f4987c 100644 --- a/trovebox/objects/photo.py +++ b/trovebox/objects/photo.py @@ -19,7 +19,15 @@ class Photo(TroveboxObject): self._delete_fields() return result - # def delete_source(self, **kwds): + def delete_source(self, **kwds): + """ + Endpoint: /photo//source/delete.json + + Deletes the source files of this photo. + Returns True if successful. + Raises a TroveboxError if not. + """ + return self._client.photo.delete_source(self, **kwds) def replace(self, photo_file, **kwds): """ Not implemented yet """