Skip to content

Commit 54000dc

Browse files
committed
Improve error handling in API and upload tests
Replaced status assertions with explicit error handling in test_api.py and test_upload.py. Now exceptions are raised with API error messages when responses are not OK, improving test reliability and clarity.
1 parent aab9a93 commit 54000dc

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

tests/api/test_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,22 @@ def test_token_right_create_dataset_rights(self):
174174
)
175175
)
176176
resp = api_su.create_dataset(":root", ds.json())
177-
pid = resp.json()["data"]["persistentId"]
178-
assert resp.json()["status"] == "OK"
177+
resp.raise_for_status()
178+
179+
resp = resp.json()
180+
pid = resp["data"]["persistentId"]
181+
182+
if resp["status"] != "OK":
183+
raise Exception(resp["message"])
179184

180185
# with pytest.raises(ApiAuthorizationError):
181186
# resp = api_nru.get_dataset(pid)
182187

183188
resp = api_su.delete_dataset(pid)
184-
assert resp.json()["status"] == "OK"
189+
resp.raise_for_status()
190+
resp = resp.json()
191+
if resp["status"] != "OK":
192+
raise Exception(resp["message"])
185193

186194
def test_token_should_not_be_exposed_on_error(self):
187195
BASE_URL = os.getenv("BASE_URL")

tests/api/test_upload.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def test_file_replacement_wo_metadata(self):
184184
is_filepid=False,
185185
)
186186

187-
response.raise_for_status()
187+
if not response.ok:
188+
raise Exception(response.json()["message"])
188189

189190
# Assert
190191
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
@@ -222,6 +223,9 @@ def test_file_replacement_w_metadata(self):
222223
json_str=df.json(),
223224
)
224225

226+
if not response.ok:
227+
raise Exception(response.json()["message"])
228+
225229
# Retrieve file ID
226230
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
227231

@@ -248,6 +252,9 @@ def test_file_replacement_w_metadata(self):
248252
is_filepid=False,
249253
)
250254

255+
if not response.ok:
256+
raise Exception(response.json()["message"])
257+
251258
# Assert
252259
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
253260
data_file = api.get_dataset(pid).json()["data"]["latestVersion"]["files"][0]

0 commit comments

Comments
 (0)