浏览代码

Support PATCH on root node. Fixes #45.

Stefano Cossu 6 年之前
父节点
当前提交
cc754e17d5
共有 2 个文件被更改,包括 22 次插入0 次删除
  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.