Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions easyDataverse/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ def upload(
str: The identifier of the uploaded dataset.
"""

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

self._validate_required_fields()

self.p_id = upload_to_dataverse(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ packages = [{ include = "easyDataverse" }]
[tool.poetry.dependencies]
python = "^3.9"
pydantic = "^2.7.1"
pydataverse = "^0.3.1"
pydataverse = "^0.3.5"
pyaml = "^24.4.0"
xmltodict = "^0.13.0"
python-forge = "18.6.0"
Expand Down
37 changes: 37 additions & 0 deletions tests/integration/test_dataset_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,43 @@ def test_creation_and_upload(
"File should be in the sub-directory"
)

@pytest.mark.integration
def test_double_upload_raises_error(
self,
credentials,
):
# Arrange
base_url, api_token = credentials
dataverse = Dataverse(
server_url=base_url,
api_token=api_token,
)

# Act
dataset = dataverse.create_dataset()

dataset.citation.title = "My dataset"
dataset.citation.subject = ["Other"]
dataset.citation.add_author(name="John Doe")
dataset.citation.add_ds_description(
value="This is a description of the dataset",
date="2024",
)
dataset.citation.add_dataset_contact(
name="John Doe",
email="[email protected]",
)

dataset.add_directory(
dirpath="./tests/fixtures",
dv_dir="some/sub/dir",
)

dataset.upload(dataverse_name="root")

with pytest.raises(ValueError):
dataset.upload(dataverse_name="root")

@pytest.mark.integration
def test_creation_and_upload_with_dataset_type(
self,
Expand Down
Loading