Skip to content

Commit aa45d13

Browse files
authored
Merge pull request #188 from gdcc/unlimited-timeout
Set `timeout` to `None` to avoid timeout errors
2 parents 0e6eff8 + 0380ea2 commit aa45d13

File tree

5 files changed

+80
-6
lines changed

5 files changed

+80
-6
lines changed

pyDataverse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
__email__ = "stefan.kasberger@univie.ac.at"
1313
__copyright__ = "Copyright (c) 2019 Stefan Kasberger"
1414
__license__ = "MIT License"
15-
__version__ = "0.3.2"
15+
__version__ = "0.3.3"
1616
__url__ = "https://github.com/GDCC/pyDataverse"
1717
__download_url__ = "https://pypi.python.org/pypi/pyDataverse"
1818
__description__ = "A Python module for Dataverse."

pyDataverse/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _sync_request(
292292
kwargs = self._filter_kwargs(kwargs)
293293

294294
try:
295-
resp = method(**kwargs, follow_redirects=True)
295+
resp = method(**kwargs, follow_redirects=True, timeout=None)
296296
if resp.status_code == 401:
297297
error_msg = resp.json()["message"]
298298
raise ApiAuthorizationError(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pyDataverse"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
description = "A Python module for Dataverse."
55
authors = [
66
"Stefan Kasberger <stefan.kasberger@univie.ac.at>",

tests/api/test_upload.py

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010

1111
class TestFileUpload:
12-
1312
def test_file_upload(self):
1413
"""
1514
Test case for uploading a file to a dataset.
@@ -46,6 +45,58 @@ def test_file_upload(self):
4645
# Assert
4746
assert response.status_code == 200, "File upload failed."
4847

48+
def test_bulk_file_upload(self, create_mock_file):
49+
"""
50+
Test case for uploading bulk files to a dataset.
51+
52+
This test is meant to check the performance of the file upload feature
53+
and that nothing breaks when uploading multiple files in line.
54+
55+
This test case performs the following steps:
56+
0. Create 50 mock files.
57+
1. Creates a dataset using the provided metadata.
58+
2. Prepares a file for upload.
59+
3. Uploads the file to the dataset.
60+
4. Asserts that the file upload was successful.
61+
62+
Raises:
63+
AssertionError: If the file upload fails.
64+
65+
"""
66+
# Arrange
67+
BASE_URL = os.getenv("BASE_URL").rstrip("/")
68+
API_TOKEN = os.getenv("API_TOKEN")
69+
70+
# Create dataset
71+
metadata = json.load(open("tests/data/file_upload_ds_minimum.json"))
72+
pid = self._create_dataset(BASE_URL, API_TOKEN, metadata)
73+
api = NativeApi(BASE_URL, API_TOKEN)
74+
75+
with tempfile.TemporaryDirectory() as tmp_dir:
76+
# Create mock files
77+
mock_files = [
78+
create_mock_file(
79+
filename=f"mock_file_{i}.txt",
80+
dir=tmp_dir,
81+
size=1024**2, # 1MB
82+
)
83+
for i in range(50)
84+
]
85+
86+
for mock_file in mock_files:
87+
# Prepare file upload
88+
df = Datafile({"pid": pid, "filename": os.path.basename(mock_file)})
89+
90+
# Act
91+
response = api.upload_datafile(
92+
identifier=pid,
93+
filename=mock_file,
94+
json_str=df.json(),
95+
)
96+
97+
# Assert
98+
assert response.status_code == 200, "File upload failed."
99+
49100
def test_file_replacement(self):
50101
"""
51102
Test case for replacing a file in a dataset.
@@ -56,7 +107,7 @@ def test_file_replacement(self):
56107
3. Replace the uploaded datafile with a mutated version.
57108
4. Verify that the file replacement was successful and the content matches the expected content.
58109
"""
59-
110+
60111
# Arrange
61112
BASE_URL = os.getenv("BASE_URL").rstrip("/")
62113
API_TOKEN = os.getenv("API_TOKEN")
@@ -79,7 +130,6 @@ def test_file_replacement(self):
79130

80131
# Act
81132
with tempfile.TemporaryDirectory() as tempdir:
82-
83133
original = open("tests/data/replace.xyz").read()
84134
mutated = "Z" + original[1::]
85135
mutated_path = os.path.join(tempdir, "replace.xyz")

tests/conftest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,27 @@ def import_datafile_full_dict():
156156
"description": "Test datafile",
157157
"restrict": False,
158158
}
159+
160+
161+
@pytest.fixture
162+
def create_mock_file():
163+
"""Returns a function that creates a mock file."""
164+
165+
def _create_mock_file(filename: str, dir: str, size: int):
166+
"""Create a mock file.
167+
168+
Args:
169+
filename (str): Filename.
170+
dir (str): Directory.
171+
size (int): Size.
172+
173+
Returns:
174+
str: Path to the file.
175+
"""
176+
path = os.path.join(dir, filename)
177+
with open(path, "wb") as f:
178+
f.write(os.urandom(size))
179+
180+
return path
181+
182+
return _create_mock_file

0 commit comments

Comments
 (0)