Skip to content

Commit ae60bf1

Browse files
committed
Add test for native upload with large file
Introduces a new integration test to verify native upload functionality with a large file. Also refactors file list formatting for improved readability in existing tests.
1 parent e4a8c93 commit ae60bf1

1 file changed

Lines changed: 49 additions & 18 deletions

File tree

tests/integration/test_native_upload.py

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
from io import BytesIO
21
import json
32
import os
43
import tempfile
4+
from io import BytesIO
55

66
import pytest
77

88
from dvuploader.dvuploader import DVUploader
99
from dvuploader.file import File
10-
1110
from dvuploader.utils import add_directory, retrieve_dataset_files
1211
from tests.conftest import create_dataset, create_mock_file, create_mock_tabular_file
1312

@@ -472,15 +471,17 @@ def test_metadata_with_zip_files_in_package(self, credentials):
472471

473472
# Arrange
474473
files = [
475-
File(filepath="tests/fixtures/archive.zip",
476-
dv_dir="subdir2",
477-
description="This file should not be unzipped",
478-
categories=["Test file"]
474+
File(
475+
filepath="tests/fixtures/archive.zip",
476+
dv_dir="subdir2",
477+
description="This file should not be unzipped",
478+
categories=["Test file"],
479479
),
480-
File(filepath="tests/fixtures/add_dir_files/somefile.txt",
481-
dv_dir="subdir",
482-
description="A simple text file",
483-
categories=["Test file"]
480+
File(
481+
filepath="tests/fixtures/add_dir_files/somefile.txt",
482+
dv_dir="subdir",
483+
description="A simple text file",
484+
categories=["Test file"],
484485
),
485486
]
486487

@@ -506,30 +507,26 @@ def test_metadata_with_zip_files_in_package(self, credentials):
506507
{
507508
"label": "archive.zip",
508509
"description": "This file should not be unzipped",
509-
"categories": ["Test file"]
510+
"categories": ["Test file"],
510511
},
511512
{
512513
"label": "somefile.txt",
513514
"description": "A simple text file",
514-
"categories": ["Test file"]
515+
"categories": ["Test file"],
515516
},
516517
]
517518

518519
files_as_expected = sorted(
519520
[
520-
{
521-
k: (f[k] if k in f else None)
522-
for k in expected_files[0].keys()
523-
}
521+
{k: (f[k] if k in f else None) for k in expected_files[0].keys()}
524522
for f in files
525523
],
526-
key=lambda x: x["label"]
524+
key=lambda x: x["label"],
527525
)
528526
assert files_as_expected == expected_files, (
529527
f"File metadata not as expected: {json.dumps(files, indent=2)}"
530528
)
531529

532-
533530
def test_too_many_zip_files(
534531
self,
535532
credentials,
@@ -558,3 +555,37 @@ def test_too_many_zip_files(
558555
dataverse_url=BASE_URL,
559556
n_parallel_uploads=10,
560557
)
558+
559+
@pytest.mark.expensive
560+
def test_native_upload_with_large_file(
561+
self,
562+
credentials,
563+
):
564+
BASE_URL, API_TOKEN = credentials
565+
566+
# Create Dataset
567+
pid = create_dataset(
568+
parent="Root",
569+
server_url=BASE_URL,
570+
api_token=API_TOKEN,
571+
)
572+
573+
with tempfile.TemporaryDirectory() as directory:
574+
path = os.path.join(directory, "large_file.bin")
575+
self._create_file(1024 * 1024 * 2, path)
576+
577+
files = [
578+
File(filepath=path),
579+
]
580+
581+
uploader = DVUploader(files=files)
582+
uploader.upload(
583+
persistent_id=pid,
584+
api_token=API_TOKEN,
585+
dataverse_url=BASE_URL,
586+
n_parallel_uploads=1,
587+
)
588+
589+
def _create_file(self, size: int, path: str):
590+
with open(path, "wb") as f:
591+
f.write(b"\0" * size)

0 commit comments

Comments
 (0)