launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #15166
[Merge] lp:~rvb/maas/file-delete3 into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/file-delete3 into lp:maas with lp:~rvb/maas/file-delete2 as a prerequisite.
Commit message:
Add support for deleting an individual FileStorage object.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1125006 in MAAS: "No API support for deleting or listing files (FileStorage objects)"
https://bugs.launchpad.net/maas/+bug/1125006
For more details, see:
https://code.launchpad.net/~rvb/maas/file-delete3/+merge/148383
--
https://code.launchpad.net/~rvb/maas/file-delete3/+merge/148383
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/file-delete3 into lp:maas.
=== modified file 'src/maasserver/api.py'
--- src/maasserver/api.py 2013-02-14 08:28:24 +0000
+++ src/maasserver/api.py 2013-02-14 08:28:24 +0000
@@ -827,7 +827,7 @@
"""
model = FileStorage
fields = DISPLAYED_FILES_FIELDS
- create = update = delete = None
+ create = update = None
def read(self, request, filename):
"""GET a FileStorage object."""
@@ -843,6 +843,13 @@
stream, mimetype='application/json; charset=utf-8',
status=httplib.OK)
+ @operation(idempotent=False)
+ def delete(self, request, filename):
+ """Delete a FileStorage object."""
+ stored_file = get_object_or_404(FileStorage, filename=filename)
+ stored_file.delete()
+ return rc.DELETED
+
@classmethod
def resource_uri(cls, stored_file=None):
filename = "filename"
=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py 2013-02-14 08:28:24 +0000
+++ src/maasserver/tests/test_api.py 2013-02-14 08:28:24 +0000
@@ -79,6 +79,7 @@
BootImage,
Config,
DHCPLease,
+ FileStorage,
MACAddress,
Node,
NodeGroup,
@@ -2642,6 +2643,14 @@
reverse('file_handler', args=[filename]))
self.assertEqual(httplib.UNAUTHORIZED, response.status_code)
+ def test_anon_cannot_delete_file(self):
+ filename = factory.make_name('file')
+ factory.make_file_storage(
+ filename=filename, content=b"test content")
+ response = self.client.delete(
+ reverse('file_handler', args=[filename]))
+ self.assertEqual(httplib.UNAUTHORIZED, response.status_code)
+
class FileStorageAPITest(FileStorageAPITestMixin, APITestCase):
@@ -2771,6 +2780,16 @@
(filename, content),
(parsed_result['filename'], parsed_result['content']))
+ def test_delete_file_deletes_file(self):
+ filename = factory.make_name('file')
+ factory.make_file_storage(
+ filename=filename, content=b"test content")
+ response = self.client.delete(
+ reverse('file_handler', args=[filename]))
+ self.assertEqual(httplib.NO_CONTENT, response.status_code)
+ self.assertFalse(
+ FileStorage.objects.filter(filename=filename).exists())
+
class TestTagAPI(APITestCase):
"""Tests for /api/1.0/tags/<tagname>/."""