Browse Source

Fix deleting resource with missing prefer header; add tombstone tests.

Stefano Cossu 7 years ago
parent
commit
2f547a2536
3 changed files with 57 additions and 4 deletions
  1. 5 0
      doc/notes/fcrepo4_deltas.md
  2. 5 3
      lakesuperior/endpoints/ldp.py
  3. 47 1
      tests/endpoints/test_ldp.py

+ 5 - 0
doc/notes/fcrepo4_deltas.md

@@ -93,6 +93,11 @@ Allowed` regardless of whether the tombstone exists or not.
 LAKEsuperior will return `405` only if the tombstone actually exists, `404`
 otherwise.
 
+## Optional deletion without leaving tombstone
+
+In LAKEsuperior, setting the `Prefer:no-tombstone` header option allows to
+delete a resource without leaving a tombstone.
+
 ## Atomicity
 
 FCREPO4 supports batch atomic operations whereas a transaction can be opened

+ 5 - 3
lakesuperior/endpoints/ldp.py

@@ -247,9 +247,11 @@ def delete_resource(uuid):
     repr_opts = {'parameters' : {'include' : Ldpr.RETURN_INBOUND_REF_URI}} \
             if current_app.config['store']['ldp_rs']['referential_integrity'] \
             else None
-    prefer = Toolbox().parse_rfc7240(request.headers['prefer'])
-    leave_tstone = 'no-tombstone' not in prefer
-    import pdb; pdb.set_trace()
+    if 'prefer' in request.headers:
+        prefer = Toolbox().parse_rfc7240(request.headers['prefer'])
+        leave_tstone = 'no-tombstone' not in prefer
+    else:
+        leave_tstone = True
 
     try:
         Ldpr.inst(uuid, repr_opts).delete(leave_tstone=leave_tstone)

+ 47 - 1
tests/endpoints/test_ldp.py

@@ -159,13 +159,21 @@ class TestLdp:
 
 
     def test_delete(self):
+        '''
+        Test delete response codes.
+        '''
         create_resp = self.client.put('/ldp/test_delete01')
         delete_resp = self.client.delete('/ldp/test_delete01')
-
         assert delete_resp.status_code == 204
 
+        bogus_delete_resp = self.client.delete('/ldp/test_delete101')
+        assert bogus_delete_resp.status_code == 404
+
 
     def test_tombstone(self):
+        '''
+        Test tombstone behaviors.
+        '''
         tstone_resp = self.client.get('/ldp/test_delete01')
         assert tstone_resp.status_code == 410
         assert tstone_resp.headers['Link'] == \
@@ -181,6 +189,27 @@ class TestLdp:
         assert self.client.get('/ldp/test_delete01').status_code == 404
 
 
+    def test_delete_recursive(self):
+        '''
+        Test response codes for resources deleted recursively and their
+        tombstones.
+        '''
+        self.client.put('/ldp/test_delete_recursive01')
+        self.client.put('/ldp/test_delete_recursive01/a')
+
+        self.client.delete('/ldp/test_delete_recursive01')
+
+        tstone_resp = self.client.get('/ldp/test_delete_recursive01')
+        assert tstone_resp.status_code == 410
+        assert tstone_resp.headers['Link'] == \
+            '<{}/test_delete_recursive01/fcr:tombstone>; rel="hasTombstone"'\
+            .format(Toolbox().base_url)
+
+        child_tstone_resp = self.client.get('/ldp/test_delete_recursive01/a')
+        assert child_tstone_resp.status_code == tstone_resp.status_code
+        assert 'Link' not in child_tstone_resp.headers.keys()
+
+
 
 @pytest.mark.usefixtures('client_class')
 @pytest.mark.usefixtures('db')
@@ -372,3 +401,20 @@ class TestPrefHeader:
             assert incl_g[ cont_subject : RDF.type : type ]
             assert not omit_g[ cont_subject : RDF.type : type ]
 
+
+    def test_delete_no_tstone(self):
+        '''
+        Test the `no-tombstone` Prefer option.
+        '''
+        self.client.put('/ldp/test_delete_no_tstone01')
+        self.client.put('/ldp/test_delete_no_tstone01/a')
+
+        self.client.delete('/ldp/test_delete_no_tstone01', headers={
+                'prefer' : 'no-tombstone'})
+
+        resp = self.client.get('/ldp/test_delete_no_tstone01')
+        assert resp.status_code == 404
+
+        child_resp = self.client.get('/ldp/test_delete_no_tstone01/a')
+        assert child_resp.status_code == 404
+