Skip to content

Commit

Permalink
add handler test case
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Apr 16, 2024
1 parent 992f1c6 commit 0e57023
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/integration/test_native_upload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from io import BytesIO
import tempfile

import pytest
from dvuploader.dvuploader import DVUploader
from dvuploader.file import File

from dvuploader.utils import add_directory, retrieve_dataset_files
from tests.conftest import create_dataset, create_mock_file
Expand Down Expand Up @@ -100,3 +102,47 @@ def test_forced_native_upload(

assert len(files) == 3
assert sorted([file["label"] for file in files]) == sorted(expected_files)


def test_native_upload_by_handler(
self,
credentials,
):
BASE_URL, API_TOKEN = credentials

# Arrange
byte_string = b"Hello, World!"
files = [
File(filepath="subdir/file.txt", handler=BytesIO(byte_string)),
File(filepath="biggerfile.txt", handler=BytesIO(byte_string*10000)),
]

# Create Dataset
pid = create_dataset(
parent="Root",
server_url=BASE_URL,
api_token=API_TOKEN,
)

# Act
uploader = DVUploader(files=files)
uploader.upload(
persistent_id=pid,
api_token=API_TOKEN,
dataverse_url=BASE_URL,
n_parallel_uploads=1,
)

# Assert
expected_files = [
"file.txt",
"biggerfile.txt",
]
files = retrieve_dataset_files(
dataverse_url=BASE_URL,
persistent_id=pid,
api_token=API_TOKEN,
)

assert len(files) == 2
assert sorted([file["label"] for file in files]) == sorted(expected_files)

0 comments on commit 0e57023

Please sign in to comment.