Skip to content

Commit d5863f5

Browse files
committed
feat.add patch_file method
issue 7
1 parent 77d5a25 commit d5863f5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/solid/solid_api.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,22 @@ def put_file(self, url, content: RequestContent, content_type, options: WriteOpt
189189
return self.put(url, request_options)
190190

191191
def patch_file(self, url, patch_content, patch_content_type) -> Response:
192-
raise Exception('Not implemented')
192+
# raise Exception('Not implemented')
193+
if url[-1] == '/':
194+
raise Exception("Cannot use patchFile to create a folder : {}".format(url))
195+
# if options.merge == MERGE.KEEP_TARGET and self.item_exists(url):
196+
# raise Exception(f'File already exists: {url}')
197+
198+
request_options = {
199+
'headers': {
200+
'Link': LINK.RESOURCE.value,
201+
'Content-Type': patch_content_type,
202+
},
203+
'content': patch_content
204+
}
205+
206+
return self.put(url, request_options)
207+
193208

194209
def read_folder(self, url, options: ReadFolderOptions = ReadFolderOptions()) -> FolderData:
195210
if url[-1] != '/':

tests/test_solid_api.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
def gen_random_str() -> str:
1414
return uuid.uuid4().hex
1515

16-
1716
POD_ENDPOINT = os.getenv('SOLID_ENDPOINT')
1817
IDP = os.getenv('SOLID_IDP')
1918
USERNAME = os.getenv('SOLID_USERNAME')
@@ -143,5 +142,16 @@ def test_file():
143142
resp = api.get(url)
144143
assert resp.text == body
145144

145+
# patch
146+
body = '#hello Solid! New World!'
147+
f = io.BytesIO(body.encode('UTF-8'))
148+
api.patch_file(url, f, 'text/markdown')
149+
150+
# retrieve
151+
resp = api.get(url)
152+
assert resp.text == body
153+
146154
# delete
147155
api.delete(url)
156+
157+

0 commit comments

Comments
 (0)