Skip to content

Commit

Permalink
fix update not adding new mult compounds
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed May 29, 2024
1 parent bbfd613 commit 4a622be
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
12 changes: 2 additions & 10 deletions easyDataverse/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,10 @@ def _add_changed_multiples(self):
if not self._is_multiple(field):
continue

value = getattr(self, name)
has_changes = any(value._changed for value in value)

if has_changes:
self._changed.add(name)
self._changed.add(name)

def _process_multiple_compound(self, compounds) -> List[Dict]:
"""Whenever a single compound has changed, return all compounds."""

if not any(len(compound._changed) for compound in compounds):
return []

"""Processes multiple compounds"""
return [compound.dataverse_dict() for compound in compounds]

def _process_single_compound(self, compound) -> Dict:
Expand Down
28 changes: 27 additions & 1 deletion tests/integration/test_dataset_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def test_dataset_update(
credentials,
minimal_upload,
):

# Arrange
base_url, api_token = credentials
url = f"{base_url}/api/dataverses/root/datasets"
Expand All @@ -38,6 +37,11 @@ def test_dataset_update(
# Fetch the dataset and update the title
dataset = dataverse.load_dataset(pid)
dataset.citation.title = "Title has changed"

# Check if multiple compound changes are tracked too
dataset.citation.add_other_id(agency="Software Heritage1", value="softwareid1")
dataset.citation.add_other_id(agency="Software Heritage2", value="softwareid2")

dataset.update()

# Re-fetch the dataset
Expand All @@ -59,10 +63,32 @@ def test_dataset_update(
)
)

other_id_fields = next(
filter(
lambda x: x["typeName"] == "otherId",
updated_dataset["data"]["metadataBlocks"]["citation"]["fields"],
)
)["value"]

# Assert
assert (
title_field["value"] == "Title has changed"
), "The updated dataset title does not match the expected title."
assert (
len(other_id_fields) == 2
), "The updated dataset does not have the expected number of other ids."
assert (
other_id_fields[0]["otherIdValue"]["value"] == "softwareid1"
), "The updated dataset does not have the expected other id."
assert (
other_id_fields[1]["otherIdValue"]["value"] == "softwareid2"
), "The updated dataset does not have the expected other id."
assert (
other_id_fields[0]["otherIdAgency"]["value"] == "Software Heritage1"
), "The updated dataset does not have the expected other id agency."
assert (
other_id_fields[1]["otherIdAgency"]["value"] == "Software Heritage2"
), "The updated dataset does not have the expected other id agency."

@staticmethod
def sort_citation(dataset: Dict):
Expand Down

0 comments on commit 4a622be

Please sign in to comment.