Skip to content

Commit 3765c49

Browse files
committed
fix. patch method and the test
1 parent d5863f5 commit 3765c49

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/solid/solid_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def patch_file(self, url, patch_content, patch_content_type) -> Response:
203203
'content': patch_content
204204
}
205205

206-
return self.put(url, request_options)
206+
return self.patch(url, request_options)
207207

208208

209209
def read_folder(self, url, options: ReadFolderOptions = ReadFolderOptions()) -> FolderData:

tests/test_solid_api.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66
from httpx import HTTPStatusError
77

88
from solid.auth import Auth
9-
from solid.solid_api import SolidAPI
9+
from solid.solid_api import SolidAPI, WriteOptions
1010
from solid.utils.api_util import append_slashes_at_end
1111

1212

1313
def gen_random_str() -> str:
1414
return uuid.uuid4().hex
1515

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+
1622
POD_ENDPOINT = os.getenv('SOLID_ENDPOINT')
1723
IDP = os.getenv('SOLID_IDP')
1824
USERNAME = os.getenv('SOLID_USERNAME')
@@ -142,16 +148,29 @@ def test_file():
142148
resp = api.get(url)
143149
assert resp.text == body
144150

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\" ."
147157
f = io.BytesIO(body.encode('UTF-8'))
148-
api.patch_file(url, f, 'text/markdown')
158+
api.create_file(patchedUrl, f, 'text/turtle', WriteOptions())
149159

150-
# retrieve
151-
resp = api.get(url)
160+
# retrieve ttl file
161+
resp = api.get(patchedUrl)
152162
assert resp.text == body
153163

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+
156175

157176

0 commit comments

Comments
 (0)