Skip to content

Commit ff52a42

Browse files
authored
Merge pull request #61 from gdcc/update-pydataverse-version
Update pyDataverse version and `upload` check
2 parents 36a56c3 + 9ef5e55 commit ff52a42

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

easyDataverse/dataset.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ def upload(
305305
str: The identifier of the uploaded dataset.
306306
"""
307307

308+
if self.p_id is not None:
309+
raise ValueError(
310+
"It seems like you are trying to upload a dataset that has already been uploaded. Please use the 'update' method instead.\n"
311+
"If you are sure that you want to upload a new version of the dataset, please set the 'p_id' field to 'None'."
312+
)
313+
308314
self._validate_required_fields()
309315

310316
self.p_id = upload_to_dataverse(

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ packages = [{ include = "easyDataverse" }]
1010
[tool.poetry.dependencies]
1111
python = "^3.9"
1212
pydantic = "^2.7.1"
13-
pydataverse = "^0.3.1"
13+
pydataverse = "^0.3.5"
1414
pyaml = "^24.4.0"
1515
xmltodict = "^0.13.0"
1616
python-forge = "18.6.0"

tests/integration/test_dataset_creation.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,43 @@ def test_creation_and_upload(
9696
"File should be in the sub-directory"
9797
)
9898

99+
@pytest.mark.integration
100+
def test_double_upload_raises_error(
101+
self,
102+
credentials,
103+
):
104+
# Arrange
105+
base_url, api_token = credentials
106+
dataverse = Dataverse(
107+
server_url=base_url,
108+
api_token=api_token,
109+
)
110+
111+
# Act
112+
dataset = dataverse.create_dataset()
113+
114+
dataset.citation.title = "My dataset"
115+
dataset.citation.subject = ["Other"]
116+
dataset.citation.add_author(name="John Doe")
117+
dataset.citation.add_ds_description(
118+
value="This is a description of the dataset",
119+
date="2024",
120+
)
121+
dataset.citation.add_dataset_contact(
122+
name="John Doe",
123+
email="john@doe.com",
124+
)
125+
126+
dataset.add_directory(
127+
dirpath="./tests/fixtures",
128+
dv_dir="some/sub/dir",
129+
)
130+
131+
dataset.upload(dataverse_name="root")
132+
133+
with pytest.raises(ValueError):
134+
dataset.upload(dataverse_name="root")
135+
99136
@pytest.mark.integration
100137
def test_creation_and_upload_with_dataset_type(
101138
self,

0 commit comments

Comments
 (0)