|
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | from databricks.sdk.core import DatabricksError |
| 11 | +from databricks.sdk.mixins.files import MultipartUploadCreate, MultipartUploadCreatePartUrlsResponse |
11 | 12 | from databricks.sdk.service.catalog import VolumeType |
12 | 13 |
|
13 | 14 |
|
@@ -228,6 +229,35 @@ def test_files_api_upload_download(ucws, random): |
228 | 229 | with w.files.download(target_file).contents as f: |
229 | 230 | assert f.read() == b"some text data" |
230 | 231 |
|
| 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 | + |
231 | 261 |
|
232 | 262 | def test_files_api_read_twice_from_one_download(ucws, random): |
233 | 263 | w = ucws |
|
0 commit comments