diff --git a/src/antares/craft/exceptions/exceptions.py b/src/antares/craft/exceptions/exceptions.py index fa06367c..a7f01a40 100644 --- a/src/antares/craft/exceptions/exceptions.py +++ b/src/antares/craft/exceptions/exceptions.py @@ -329,6 +329,11 @@ def __init__(self, study_id: str, message: str) -> None: self.message = f"Could not get outputs for {study_id}: " + message super().__init__(self.message) +class OutputDeletionError(Exception): + def __init__(self, study_id: str, output_name:str, message: str) -> None: + self.message = f"Could not delete the output {output_name} from study {study_id}: " + message + super().__init__(self.message) + class AggregateCreationError(Exception): def __init__(self, study_id: str, output_id: str, mc_type: str, object_type: str, message: str) -> None: diff --git a/src/antares/craft/model/study.py b/src/antares/craft/model/study.py index e74815f9..8a31e201 100644 --- a/src/antares/craft/model/study.py +++ b/src/antares/craft/model/study.py @@ -403,9 +403,11 @@ def get_output(self, output_id: str) -> Output: def delete_outputs(self) -> None: self._study_service.delete_outputs() + self._outputs.clear() def delete_output(self, output_name: str) -> None: self._study_service.delete_output(output_name) + self._outputs.pop(output_name) def _verify_study_already_exists(study_directory: Path) -> None: if study_directory.exists(): diff --git a/src/antares/craft/service/api_services/study_api.py b/src/antares/craft/service/api_services/study_api.py index 2c6cdd66..3c5183e2 100644 --- a/src/antares/craft/service/api_services/study_api.py +++ b/src/antares/craft/service/api_services/study_api.py @@ -21,7 +21,7 @@ OutputsRetrievalError, StudyDeletionError, StudySettingsUpdateError, - StudyVariantCreationError, + StudyVariantCreationError, OutputDeletionError, ) from antares.craft.model.binding_constraint import BindingConstraint from antares.craft.model.output import Output @@ -143,7 +143,19 @@ def read_outputs(self) -> list[Output]: raise OutputsRetrievalError(self.study_id, e.message) def delete_outputs(self) -> None: - pass + outputs_url = f"{self._base_url}/studies/{self.study_id}/outputs" + try: + response = self._wrapper.get(outputs_url) + outputs_json_list = response.json() + for output in outputs_json_list: + output_name = output["name"] + self.delete_output(output_name) + except APIError as e: + raise OutputsRetrievalError(self.study_id, e.message) def delete_output(self, output_name: str) -> None: - pass + url = f"{self._base_url}/studies/{self.study_id}/outputs/{output_name}" + try: + self._wrapper.delete(url) + except APIError as e: + raise OutputDeletionError(self.study_id, output_name, e.message) from e