|
6 | 6 | from httpx import HTTPStatusError |
7 | 7 |
|
8 | 8 | from solid.auth import Auth |
9 | | -from solid.solid_api import SolidAPI |
| 9 | +from solid.solid_api import SolidAPI, WriteOptions |
10 | 10 | from solid.utils.api_util import append_slashes_at_end |
11 | 11 |
|
12 | 12 |
|
13 | 13 | def gen_random_str() -> str: |
14 | 14 | return uuid.uuid4().hex |
15 | 15 |
|
| 16 | +def parse_turtle(turtle: str) -> str: |
| 17 | + lines = turtle.split('\n') |
| 18 | + for line in lines: |
| 19 | + if line.startswith('<> dct'): |
| 20 | + return line |
16 | 21 |
|
17 | 22 | POD_ENDPOINT = os.getenv('SOLID_ENDPOINT') |
18 | 23 | IDP = os.getenv('SOLID_IDP') |
@@ -145,3 +150,27 @@ def test_file(): |
145 | 150 |
|
146 | 151 | # delete |
147 | 152 | api.delete(url) |
| 153 | + |
| 154 | + # patch - create ttl file |
| 155 | + patchedUrl = url + '.ttl' |
| 156 | + body = "<> <http://purl.org/dc/terms/title> \"This is a test file\" .\n<> <http://www.w3.org/2000/10/swap/pim/contact#fullName> \"Eric Miller\" ." |
| 157 | + f = io.BytesIO(body.encode('UTF-8')) |
| 158 | + api.create_file(patchedUrl, f, 'text/turtle', WriteOptions()) |
| 159 | + |
| 160 | + # retrieve ttl file |
| 161 | + resp = api.get(patchedUrl) |
| 162 | + assert resp.text == body |
| 163 | + |
| 164 | + # patch - update ttl file |
| 165 | + body = "DELETE DATA { <> <http://www.w3.org/2000/10/swap/pim/contact#fullName> \"Eric Miller\" };\nINSERT DATA { <> <http://www.w3.org/2000/10/swap/pim/contact#personalTitle> \"Dr.\" }" |
| 166 | + f = io.BytesIO(body.encode('UTF-8')) |
| 167 | + api.patch_file(patchedUrl, f, 'application/sparql-update') |
| 168 | + |
| 169 | + # retrieve updated ttl file |
| 170 | + resp = api.get(patchedUrl) |
| 171 | + patchedBody = '<> dct:title "This is a test file"; contact:personalTitle "Dr.".' |
| 172 | + assert parse_turtle(resp.text) == patchedBody |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + |
0 commit comments