Browse Source

Only call check_rsrc_status if strict is True; disable test for embedded children;
fix doc typos.

Stefano Cossu 6 years ago
parent
commit
ea82d57995

+ 1 - 1
conftest.py

@@ -32,7 +32,7 @@ def db(app):
 
     yield db
 
-    print('Tearing down fixure graph store.')
+    print('Tearing down fixture graph store.')
     for g in db.ds.graphs():
         db.ds.remove_graph(g)
 

+ 11 - 2
lakesuperior/model/ldpr.py

@@ -742,8 +742,17 @@ class Ldpr(metaclass=ABCMeta):
         #    if not isinstance(trp, set):
         #        trp = set(trp)
 
-        type = self.types
-        actor = self.metadata.value(nsc['fcrepo'].createdBy)
+        try:
+            type = self.types
+            actor = self.metadata.value(nsc['fcrepo'].createdBy)
+        except ResourceNotExistsError:
+            type = set()
+            actor = None
+            for t in add_trp:
+                if t[1] == RDF.type:
+                    type.add(t[2])
+                elif actor is None and t[1] == nsc['fcrepo'].createdBy:
+                    actor = t[2]
 
         ret = self.rdfly.modify_rsrc(self.uid, remove_trp, add_trp)
 

+ 24 - 21
lakesuperior/store_layouts/ldp_rs/rsrc_centric_layout.py

@@ -197,12 +197,12 @@ class RsrcCentricLayout:
 
         #self._logger.debug('Found resource: {}'.format(
         #        gr.serialize(format='turtle').decode('utf-8')))
-        if strict and not len(gr):
-            raise ResourceNotExistsError(uid)
-
         rsrc = Resource(gr, nsc['fcres'][uid])
 
-        return self._check_rsrc_status(rsrc, strict)
+        if strict:
+            self._check_rsrc_status(rsrc)
+
+        return rsrc
 
 
     def ask_rsrc_exists(self, uid):
@@ -223,8 +223,10 @@ class RsrcCentricLayout:
             uid = self.snapshot_uid(uid, ver_uid)
         gr = self.ds.graph(nsc['fcadmin'][uid]) | Graph()
         rsrc = Resource(gr, nsc['fcres'][uid])
+        if strict:
+            self._check_rsrc_status(rsrc)
 
-        return self._check_rsrc_status(rsrc, strict)
+        return rsrc
 
 
     def get_version_info(self, uid, strict=True):
@@ -250,8 +252,10 @@ class RsrcCentricLayout:
             'ag': nsc['fcadmin'][uid],
             's': nsc['fcres'][uid]})
         rsrc = Resource(gr, nsc['fcres'][uid])
+        if strict:
+            self._check_rsrc_status(rsrc)
 
-        return self._check_rsrc_status(rsrc, strict)
+        return rsrc
 
 
     def get_inbound_rel(self, uri):
@@ -260,6 +264,7 @@ class RsrcCentricLayout:
 
         @param subj_uri Subject URI.
         '''
+        # Only search in non-historic graphs.
         qry = '''
         CONSTRUCT { ?s1 ?p1 ?s }
         WHERE {
@@ -384,25 +389,23 @@ class RsrcCentricLayout:
 
     ## PROTECTED MEMBERS ##
 
-    def _check_rsrc_status(self, rsrc, strict):
+    def _check_rsrc_status(self, rsrc):
+        '''
+        Check if a resource is not existing or if it is a tombstone.
+        '''
+        uid = g.tbox.uri_to_uuid(rsrc.identifier)
+        if not len(rsrc.graph):
+            raise ResourceNotExistsError(uid)
+
         # Check if resource is a tombstone.
         if rsrc[RDF.type : nsc['fcsystem'].Tombstone]:
-            if strict:
-                raise TombstoneError(
-                        g.tbox.uri_to_uuid(rsrc.identifier),
-                        rsrc.value(nsc['fcrepo'].created))
-            else:
-                self._logger.info('Tombstone found: {}'.format(uid))
+            raise TombstoneError(
+                    uid, rsrc.value(nsc['fcrepo'].created))
         elif rsrc.value(nsc['fcsystem'].tombstone):
-            if strict:
-                raise TombstoneError(
-                        g.tbox.uri_to_uuid(
-                            rsrc.value(nsc['fcsystem'].tombstone).identifier),
+            raise TombstoneError(
+                    g.tbox.uri_to_uuid(
+                        rsrc.value(nsc['fcsystem'].tombstone).identifier),
                         rsrc.value(nsc['fcrepo'].created))
-            else:
-                self._logger.info('Parent tombstone found: {}'.format(uri))
-
-        return rsrc
 
 
     def _parse_construct(self, qry, init_bindings={}):

+ 4 - 3
tests/endpoints/test_ldp.py

@@ -509,7 +509,8 @@ class TestPrefHeader:
         assert rsp_strict.status_code == 412
 
 
-    def test_embed_children(self, cont_structure):
+    # @HOLD Embed children is debated.
+    def _disabled_test_embed_children(self, cont_structure):
         '''
         verify the "embed children" prefer header.
         '''
@@ -572,12 +573,12 @@ class TestPrefHeader:
 
         children = incl_gr[cont_subject : nsc['ldp'].contains]
         for child_uri in children:
-            assert not omit_gr[ cont_subject : nsc['ldp'].contains : child_uri ]
+            assert not omit_gr[cont_subject : nsc['ldp'].contains : child_uri]
 
 
     def test_inbound_rel(self, cont_structure):
         '''
-        verify the "inboud relationships" prefer header.
+        verify the "inbound relationships" prefer header.
         '''
         parent_path = cont_structure['path']
         cont_resp = cont_structure['response']