Browse Source

Merge pull request #50 from scossu/fix_45

Support PATCH on root node. Fixes #45.
Stefano Cossu 6 years ago
parent
commit
f18fcad572
2 changed files with 22 additions and 0 deletions
  1. 2 0
      lakesuperior/endpoints/ldp.py
  2. 20 0
      tests/endpoints/test_ldp.py

+ 2 - 0
lakesuperior/endpoints/ldp.py

@@ -312,6 +312,8 @@ def put_resource(uid):
 
 
 @ldp.route('/<path:uid>', methods=['PATCH'], strict_slashes=False)
+@ldp.route('/', defaults={'uid': '/'}, methods=['PATCH'],
+        strict_slashes=False)
 def patch_resource(uid, is_metadata=False):
     """
     https://www.w3.org/TR/ldp/#ldpr-HTTP_PATCH

+ 20 - 0
tests/endpoints/test_ldp.py

@@ -298,6 +298,26 @@ class TestLdp:
         assert self.client.post('/ldp/post_409').status_code == 409
 
 
+    def test_patch_root(self):
+        '''
+        Test patching root node.
+        '''
+        path = '/ldp/'
+        self.client.get(path)
+        uri = g.webroot + '/'
+
+        with open('tests/data/sparql_update/simple_insert.sparql') as data:
+            resp = self.client.patch(path,
+                    data=data,
+                    headers={'content-type' : 'application/sparql-update'})
+
+        assert resp.status_code == 204
+
+        resp = self.client.get(path)
+        gr = Graph().parse(data=resp.data, format='text/turtle')
+        assert gr[ URIRef(uri) : nsc['dc'].title : Literal('Hello') ]
+
+
     def test_patch(self):
         '''
         Test patching a resource.