|
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 |
| 21 | + |
16 | 22 | POD_ENDPOINT = os.getenv('SOLID_ENDPOINT') |
17 | 23 | IDP = os.getenv('SOLID_IDP') |
18 | 24 | USERNAME = os.getenv('SOLID_USERNAME') |
@@ -142,16 +148,29 @@ def test_file(): |
142 | 148 | resp = api.get(url) |
143 | 149 | assert resp.text == body |
144 | 150 |
|
145 | | - # patch |
146 | | - body = '#hello Solid! New World!' |
| 151 | + # delete |
| 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\" ." |
147 | 157 | f = io.BytesIO(body.encode('UTF-8')) |
148 | | - api.patch_file(url, f, 'text/markdown') |
| 158 | + api.create_file(patchedUrl, f, 'text/turtle', WriteOptions()) |
149 | 159 |
|
150 | | - # retrieve |
151 | | - resp = api.get(url) |
| 160 | + # retrieve ttl file |
| 161 | + resp = api.get(patchedUrl) |
152 | 162 | assert resp.text == body |
153 | 163 |
|
154 | | - # delete |
155 | | - api.delete(url) |
| 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 | + |
156 | 175 |
|
157 | 176 |
|
0 commit comments