diff --git a/easyDataverse/dataset.py b/easyDataverse/dataset.py index 5f14247..4698e23 100644 --- a/easyDataverse/dataset.py +++ b/easyDataverse/dataset.py @@ -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( diff --git a/pyproject.toml b/pyproject.toml index a708295..f95400c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/integration/test_dataset_creation.py b/tests/integration/test_dataset_creation.py index 612631d..1caf391 100644 --- a/tests/integration/test_dataset_creation.py +++ b/tests/integration/test_dataset_creation.py @@ -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="john@doe.com", + ) + + 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,