From 08b3848fb65a4eacaeaaffb36cd0efccced52fdc Mon Sep 17 00:00:00 2001 From: salemsd <salem.saoudi@rte-france.com> Date: Thu, 9 Jan 2025 08:15:15 +0100 Subject: [PATCH] feat(api): some test refactoring --- .../services/api_services/test_study_api.py | 21 +++++++++++-------- tests/integration/test_web_client.py | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/tests/antares/services/api_services/test_study_api.py b/tests/antares/services/api_services/test_study_api.py index c1c0c36..19d7eae 100644 --- a/tests/antares/services/api_services/test_study_api.py +++ b/tests/antares/services/api_services/test_study_api.py @@ -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): @@ -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() diff --git a/tests/integration/test_web_client.py b/tests/integration/test_web_client.py index 56b1d76..a707918 100644 --- a/tests/integration/test_web_client.py +++ b/tests/integration/test_web_client.py @@ -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)