Add photo.delete_source endpoint
This commit is contained in:
parent
dc03fd2dfc
commit
3da64a59cc
4 changed files with 66 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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, _):
|
||||
|
|
|
@ -71,6 +71,18 @@ class ApiPhoto(ApiBase):
|
|||
self._extract_id(photo),
|
||||
**kwds)["result"]
|
||||
|
||||
def delete_source(self, photo, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/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()
|
||||
|
|
|
@ -19,7 +19,15 @@ class Photo(TroveboxObject):
|
|||
self._delete_fields()
|
||||
return result
|
||||
|
||||
# def delete_source(self, **kwds):
|
||||
def delete_source(self, **kwds):
|
||||
"""
|
||||
Endpoint: /photo/<id>/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 """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue