@@ -63,6 +63,69 @@ def test_dataset_update(
6363 "The updated dataset title does not match the expected title."
6464 )
6565
66+ @pytest .mark .integration
67+ def test_dataset_update_with_multiple_fields (
68+ self ,
69+ credentials ,
70+ ):
71+ # Arrange
72+ base_url , api_token = credentials
73+ dataverse = Dataverse (
74+ server_url = base_url ,
75+ api_token = api_token ,
76+ )
77+
78+ # Create a dataset
79+ dataset = dataverse .create_dataset ()
80+ dataset .citation .title = "My dataset"
81+ dataset .citation .subject = ["Other" ]
82+ dataset .citation .add_author (name = "John Doe" )
83+ dataset .citation .add_ds_description (
84+ value = "This is a description of the dataset" ,
85+ date = "2024" ,
86+ )
87+ dataset .citation .add_dataset_contact (
88+ name = "John Doe" ,
89+ email = "john@doe.com" ,
90+ )
91+
92+ pid = dataset .upload ("Root" )
93+
94+ # Act
95+ # Re-fetch the dataset and add other ID
96+ dataset = dataverse .load_dataset (pid )
97+ dataset .citation .add_other_id (agency = "DOI" , value = "10.5072/easy-dataverse" )
98+ dataset .update ()
99+
100+ # Re-fetch the dataset to verify the update
101+ url = (
102+ f"{ base_url } /api/datasets/:persistentId/versions/:draft?persistentId={ pid } "
103+ )
104+
105+ response = httpx .get (
106+ url ,
107+ headers = {"X-Dataverse-key" : api_token },
108+ )
109+
110+ response .raise_for_status ()
111+ updated_dataset = response .json ()
112+ other_id_field = next (
113+ filter (
114+ lambda x : x ["typeName" ] == "otherId" ,
115+ updated_dataset ["data" ]["metadataBlocks" ]["citation" ]["fields" ],
116+ ),
117+ None ,
118+ )
119+
120+ # Assert
121+ assert other_id_field is not None , "Other ID field should be present"
122+ assert len (other_id_field ["value" ]) > 0 , "Other ID field should have values"
123+ assert any (
124+ item ["otherIdAgency" ]["value" ] == "DOI"
125+ and item ["otherIdValue" ]["value" ] == "10.5072/easy-dataverse"
126+ for item in other_id_field ["value" ]
127+ ), "The DOI other ID should be present in the updated dataset"
128+
66129 @staticmethod
67130 def sort_citation (dataset : Dict ):
68131 citation = dataset ["datasetVersion" ]["metadataBlocks" ]["citation" ]
0 commit comments