Skip to content

Commit

Permalink
feat(api): some test refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
salemsd committed Jan 9, 2025
1 parent cb01174 commit 08b3848
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
21 changes: 12 additions & 9 deletions tests/antares/services/api_services/test_study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,18 @@ def test_output_aggregate_values(self):
def test_delete_output(self):
output_name = "test_output"
with requests_mock.Mocker() as mocker:
delete_url = f"https://antares.com/api/v1/studies/{self.study_id}/outputs/{output_name}"
outputs_url = f"https://antares.com/api/v1/studies/{self.study_id}/outputs"
delete_url = f"{outputs_url}/{output_name}"
mocker.get(outputs_url, json=[{"name": output_name, "archived": False}], status_code=200)
mocker.delete(delete_url, status_code=200)

self.study._outputs[output_name] = Output(name=output_name, archived=False, output_service=Mock())
self.study.read_outputs()
self.study.delete_output(output_name)

assert output_name not in self.study.get_outputs()

# failing
error_message = "Output deletion failed"
error_message = f"Output {output_name} deletion failed"
mocker.delete(delete_url, json={"description": error_message}, status_code=404)

with pytest.raises(OutputDeletionError, match=error_message):
Expand All @@ -631,16 +633,17 @@ def test_delete_outputs(self):
mocker.delete(delete_url1, status_code=200)
mocker.delete(delete_url2, status_code=200)

self.study._outputs = {
"output1": Output(name="output1", archived=False, output_service=Mock()),
"output2": Output(name="output2", archived=True, output_service=Mock()),
}
self.study.delete_outputs()
mocker.get(outputs_url, json=[
{"name": "output1", "archived": False},
{"name": "output2", "archived": True}
], status_code=200)
assert len(self.study.read_outputs()) == 2

self.study.delete_outputs()
assert len(self.study.get_outputs()) == 0

# failing
error_message = "Output deletion failed"
error_message = "Outputs deletion failed"
mocker.get(outputs_url, json={"description": error_message}, status_code=404)
with pytest.raises(OutputsRetrievalError, match=error_message):
self.study.delete_outputs()
2 changes: 1 addition & 1 deletion tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
study.wait_job_completion(
study.run_antares_simulation(AntaresSimulationParameters(output_suffix="3")), time_out=60
)
study.read_outputs()
assert len(study.read_outputs()) == 3

# delete_output
study.delete_output(output.name)
Expand Down

0 comments on commit 08b3848

Please sign in to comment.