diff --git a/antarest/study/storage/variantstudy/model/command/remove_area.py b/antarest/study/storage/variantstudy/model/command/remove_area.py index 39b1058a01..5a90bfa33b 100644 --- a/antarest/study/storage/variantstudy/model/command/remove_area.py +++ b/antarest/study/storage/variantstudy/model/command/remove_area.py @@ -237,8 +237,10 @@ def _apply(self, study_data: FileStudy) -> CommandOutput: study_data.tree.delete(["input", "hydro", "common", "capacity", f"waterValues_{self.id}"]) if study_data.config.version >= 810: - study_data.tree.delete(["input", "renewables", "clusters", self.id]) - study_data.tree.delete(["input", "renewables", "series", self.id]) + with contextlib.suppress(ChildNotFoundError): + # renewables folder only exist in tree if study.renewable-generation-modelling is "clusters" + study_data.tree.delete(["input", "renewables", "clusters", self.id]) + study_data.tree.delete(["input", "renewables", "series", self.id]) if study_data.config.version >= 860: study_data.tree.delete(["input", "st-storage", "clusters", self.id]) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index f0eb8491f1..55c1073168 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -625,8 +625,11 @@ def test_area_management(client: TestClient, admin_access_token: str) -> None: ] res = client.put(f"/v1/studies/{study_id}/layers/1?name=test2") + assert res.status_code in {200, 201}, res.json() res = client.put(f"/v1/studies/{study_id}/layers/1", json=["area 1"]) + assert res.status_code in {200, 201}, res.json() res = client.put(f"/v1/studies/{study_id}/layers/1", json=["area 2"]) + assert res.status_code in {200, 201}, res.json() res = client.get(f"/v1/studies/{study_id}/layers") assert res.json() == [ LayerInfoDTO(id="0", name="All", areas=["area 1", "area 2"]).dict(), diff --git a/tests/variantstudy/model/command/test_remove_area.py b/tests/variantstudy/model/command/test_remove_area.py index af9a0b26f7..8849bffbd3 100644 --- a/tests/variantstudy/model/command/test_remove_area.py +++ b/tests/variantstudy/model/command/test_remove_area.py @@ -24,9 +24,7 @@ class TestRemoveArea: - @pytest.mark.parametrize("empty_study", ["empty_study_810.zip", "empty_study_840.zip"], indirect=True) - def test_apply(self, empty_study: FileStudy, command_context: CommandContext): - # noinspection SpellCheckingInspection + def _set_up(self, empty_study: FileStudy, command_context: CommandContext): empty_study.tree.save( { "input": { @@ -56,6 +54,19 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext): create_area_command: ICommand = CreateArea(area_name=area_name, command_context=command_context) output = create_area_command.apply(study_data=empty_study) assert output.status, output.message + return empty_study, area_id + + @pytest.mark.parametrize("empty_study", ["empty_study_810.zip"], indirect=True) + def test_remove_with_aggregated(self, empty_study: FileStudy, command_context: CommandContext): + (empty_study, area_id) = self._set_up(empty_study, command_context) + remove_area_command = RemoveArea(id=area_id, command_context=command_context) + output = remove_area_command.apply(study_data=empty_study) + assert output.status, output.message + + @pytest.mark.parametrize("empty_study", ["empty_study_810.zip", "empty_study_840.zip"], indirect=True) + def test_apply(self, empty_study: FileStudy, command_context: CommandContext): + # noinspection SpellCheckingInspection + (empty_study, area_id) = self._set_up(empty_study, command_context) create_district_command = CreateDistrict( name="foo",