def test_hard_delete(self): """ Hard-delete (forget) a resource. """ uid = '/test_hard_delete01' rsrc_api.create_or_replace(uid) rsrc_api.delete(uid, False) with pytest.raises(ResourceNotExistsError): rsrc_api.get(uid) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect(uid)
def test_resurrect(self): """ Restore (resurrect) a soft-deleted resource. """ uid = '/test_soft_delete02' rsrc_api.create_or_replace(uid) rsrc_api.delete(uid) rsrc_api.resurrect(uid) rsrc = rsrc_api.get(uid) with env.app_globals.rdf_store.txn_ctx(): assert nsc['ldp'].Resource in rsrc.ldp_types
def test_resurrect_children(self): """ Resurrect a resource with its children. This uses fixtures from the previous test. """ uid = '/test_soft_delete_children01' rsrc_api.resurrect(uid) parent_rsrc = rsrc_api.get(uid) with env.app_globals.rdf_store.txn_ctx(): assert nsc['ldp'].Resource in parent_rsrc.ldp_types for i in range(3): child_rsrc = rsrc_api.get('{}/child{}'.format(uid, i)) with env.app_globals.rdf_store.txn_ctx(): assert nsc['ldp'].Resource in child_rsrc.ldp_types
def tombstone(uid): """ Handle all tombstone operations. The only allowed methods are POST and DELETE; any other verb will return a 405. """ try: rsrc_api.get(uid) except exc.TombstoneError as e: if request.method == 'DELETE': if e.uid == uid: rsrc_api.delete(uid, False) return '', 204 else: return _tombstone_response(e, uid) elif request.method == 'POST': if e.uid == uid: rsrc_uri = rsrc_api.resurrect(uid) headers = {'Location': rsrc_uri} return rsrc_uri, 201, headers else: return _tombstone_response(e, uid) else: return 'Method Not Allowed.', 405 except exc.ResourceNotExistsError as e: return str(e), 404 else: return '', 404
def test_delete_children(self): """ Soft-delete a resource with children. """ uid = '/test_soft_delete_children01' rsrc_api.create_or_replace(uid) for i in range(3): rsrc_api.create_or_replace('{}/child{}'.format(uid, i)) rsrc_api.delete(uid) with pytest.raises(TombstoneError): rsrc_api.get(uid) for i in range(3): with pytest.raises(TombstoneError): rsrc_api.get('{}/child{}'.format(uid, i)) # Cannot resurrect children of a tombstone. with pytest.raises(TombstoneError): rsrc_api.resurrect('{}/child{}'.format(uid, i))
def test_hard_delete_children(self): """ Hard-delete (forget) a resource with its children. This uses fixtures from the previous test. """ uid = '/test_hard_delete_children01' rsrc_api.create_or_replace(uid) for i in range(3): rsrc_api.create_or_replace('{}/child{}'.format(uid, i)) rsrc_api.delete(uid, False) with pytest.raises(ResourceNotExistsError): rsrc_api.get(uid) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect(uid) for i in range(3): with pytest.raises(ResourceNotExistsError): rsrc_api.get('{}/child{}'.format(uid, i)) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect('{}/child{}'.format(uid, i))
def test_hard_delete_descendants(self): """ Forget a resource with all its descendants. """ uid = '/test_hard_delete_descendants01' rsrc_api.create_or_replace(uid) for i in range(1, 4): rsrc_api.create_or_replace('{}/child{}'.format(uid, i)) for j in range(i): rsrc_api.create_or_replace('{}/child{}/grandchild{}'.format( uid, i, j)) rsrc_api.delete(uid, False) with pytest.raises(ResourceNotExistsError): rsrc_api.get(uid) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect(uid) for i in range(1, 4): with pytest.raises(ResourceNotExistsError): rsrc_api.get('{}/child{}'.format(uid, i)) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect('{}/child{}'.format(uid, i)) for j in range(i): with pytest.raises(ResourceNotExistsError): rsrc_api.get('{}/child{}/grandchild{}'.format( uid, i, j)) with pytest.raises(ResourceNotExistsError): rsrc_api.resurrect('{}/child{}/grandchild{}'.format( uid, i, j))