Skip to content

Commit 5a4de7a

Browse files
committed
Add integration test for baremetal API
1 parent 0b07020 commit 5a4de7a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

databricks/sdk/mixins/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def _files_multipart_upload_complete(self, file_path: str, session_token: str, e
724724
body={'etags': etags})
725725
return
726726

727-
def _ps_multipart_upload_create_part_urls(self, session_token: str, page_token: str, page_size: int):
727+
def multipart_upload_create_part_urls(self, session_token: str, *, page_token: str, page_size: int) -> MultipartUploadCreatePartUrlsResponse:
728728
"""Request a set of presigned URLs for uploading parts of a file in a multipart upload session."""
729729

730730
headers = {'Accept': 'application/json', 'Content-Type': 'application/json'}
@@ -762,7 +762,9 @@ def execute_presigned_url_request(self,
762762
"Not all client-provided headers are populated") # TODO: Move to a dedicated exception type
763763

764764
request_headers = {**presigned_url.headers, **headers}
765-
self._api.do(presigned_url.method, presigned_url.url, headers=request_headers, data=data)
765+
resp_headers = {}
766+
resp = self._api.do(presigned_url.method, presigned_url.url, headers=request_headers, data=data, response_headers = resp_headers)
767+
return (resp, resp_headers)
766768

767769

768770
class PresignedUrl:

tests/integration/test_files.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from databricks.sdk.core import DatabricksError
11+
from databricks.sdk.mixins.files import MultipartUploadCreate, MultipartUploadCreatePartUrlsResponse
1112
from databricks.sdk.service.catalog import VolumeType
1213

1314

@@ -228,6 +229,35 @@ def test_files_api_upload_download(ucws, random):
228229
with w.files.download(target_file).contents as f:
229230
assert f.read() == b"some text data"
230231

232+
def test_files_multipart_upload_download_baremetal(ucws, random):
233+
w = ucws
234+
schema = 'filesit-' + random()
235+
volume = 'filesit-' + random()
236+
with ResourceWithCleanup.create_schema(w, 'main', schema):
237+
with ResourceWithCleanup.create_volume(w, 'main', schema, volume):
238+
f = io.BytesIO(b"some text data")
239+
target_file = f'/Volumes/main/{schema}/{volume}/filesit-with-?-and-#-{random()}.txt'
240+
241+
## Create a session, upload the file in a single part, and then finalize the session
242+
session: MultipartUploadCreate = w.files.multipart_upload_create(target_file)
243+
244+
url_page_one: MultipartUploadCreatePartUrlsResponse = w.files.multipart_upload_create_part_urls(session.session_token, page_size=1)
245+
246+
# Verify that a second page of URLs may be requested
247+
w.files.multipart_upload_create_part_urls(session.session_token, page_token=url_page_one.next_page_token, page_size=1)
248+
249+
250+
(part_upload_resp, part_upload_resp_headers) = w.files.execute_presigned_url_request(url_page_one.upload_part_urls[0], data=f)
251+
print(part_upload_resp)
252+
print(part_upload_resp_headers)
253+
254+
w.files.multipart_upload_complete(target_file, session.session_token, [part_upload_resp_headers["etag"]])
255+
256+
## Download the file & assert that it's what we expect
257+
with w.files.download(target_file).contents as f:
258+
assert f.read() == b"some text data"
259+
260+
231261

232262
def test_files_api_read_twice_from_one_download(ucws, random):
233263
w = ucws

0 commit comments

Comments
 (0)