Stefano Cossu 6 éve
szülő
commit
695beb3847

+ 1 - 0
lakesuperior/dictionaries/srv_mgd_terms.py

@@ -12,6 +12,7 @@ srv_mgd_predicates = {
     nsc['fcrepo'].lastModified,
     nsc['fcrepo'].lastModifiedBy,
     nsc['fcrepo'].writable,
+    nsc['fcsystem'].fragmentOf,
     nsc['iana'].describedBy,
     nsc['ldp'].contains,
     nsc['premis'].hasMessageDigest,

+ 2 - 1
lakesuperior/model/ldp_rs.py

@@ -48,7 +48,8 @@ class LdpRs(Ldpr):
         '''
         local_update_str = g.tbox.localize_ext_str(update_str, self.urn)
         delta = self._sparql_delta(local_update_str)
-        self._ensure_single_subject_rdf(delta[0] | delta[1])
+        self._ensure_single_subject_rdf(delta[0], add_fragment=False)
+        self._ensure_single_subject_rdf(delta[1])
 
         return self._modify_rsrc(self.RES_UPDATED, *delta)
 

+ 5 - 2
lakesuperior/model/ldpr.py

@@ -739,7 +739,7 @@ class Ldpr(metaclass=ABCMeta):
         return ret
 
 
-    def _ensure_single_subject_rdf(self, gr):
+    def _ensure_single_subject_rdf(self, gr, add_fragment=True):
         '''
         Ensure that a RDF payload for a POST or PUT has a single resource.
         '''
@@ -749,7 +749,10 @@ class Ldpr(metaclass=ABCMeta):
                 parts = s.split('#')
                 frag = s
                 s = URIRef(parts[0])
-                gr.add((frag, nsc['fcsystem'].fragmentOf, s))
+                if add_fragment:
+                    # @TODO This is added to the main graph. It should be added
+                    # to the metadata graph.
+                    gr.add((frag, nsc['fcsystem'].fragmentOf, s))
             if not s == self.urn:
                 raise SingleSubjectError(s, self.uuid)
 

+ 7 - 0
tests/data/fragments_delete.sparql

@@ -0,0 +1,7 @@
+PREFIX : <http://ex.org/>
+DELETE {
+  <#hash1234> ?p ?o .
+}
+WHERE {
+  <#hash1234> ?p ?o .
+}

+ 5 - 0
tests/data/fragments_insert.sparql

@@ -0,0 +1,5 @@
+PREFIX : <http://ex.org/>
+INSERT {
+  <#hash1234> :p3 :o3 .
+}
+WHERE {}

+ 36 - 1
tests/endpoints/test_ldp.py

@@ -395,7 +395,7 @@ class TestLdp:
 
     def test_put_fragments(self):
         '''
-        Test the correct handling of fragment URIs.
+        Test the correct handling of fragment URIs on PUT and GET.
         '''
         with open('tests/data/fragments.ttl', 'rb') as f:
             self.client.put(
@@ -413,6 +413,41 @@ class TestLdp:
                 : URIRef('http://ex.org/p2') : URIRef('http://ex.org/o2')]
 
 
+    def test_patch_fragments(self):
+        '''
+        Test the correct handling of fragment URIs on PATCH.
+        '''
+        self.client.put('/ldp/test_fragment_patch')
+
+        with open('tests/data/fragments_insert.sparql', 'rb') as f:
+            self.client.patch(
+                '/ldp/test_fragment_patch',
+                headers={
+                    'Content-Type' : 'application/sparql-update',
+                },
+                data=f
+            )
+        ins_rsp = self.client.get('/ldp/test_fragment_patch')
+        ins_gr = Graph().parse(data=ins_rsp.data, format='text/turtle')
+        assert ins_gr[
+                URIRef(g.webroot + '/test_fragment_patch#hash1234')
+                : URIRef('http://ex.org/p3') : URIRef('http://ex.org/o3')]
+
+        with open('tests/data/fragments_delete.sparql', 'rb') as f:
+            self.client.patch(
+                '/ldp/test_fragment_patch',
+                headers={
+                    'Content-Type' : 'application/sparql-update',
+                },
+                data=f
+            )
+        del_rsp = self.client.get('/ldp/test_fragment_patch')
+        del_gr = Graph().parse(data=del_rsp.data, format='text/turtle')
+        assert not del_gr[
+                URIRef(g.webroot + '/test_fragment_patch#hash1234')
+                : URIRef('http://ex.org/p3') : URIRef('http://ex.org/o3')]
+
+
 @pytest.mark.usefixtures('client_class')
 @pytest.mark.usefixtures('db')
 class TestPrefHeader: