Skip to content

Commit

Permalink
fix(area): allow removal when aggregated mode used
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jul 16, 2024
1 parent b4fec58 commit 5a5136e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 14 additions & 3 deletions tests/variantstudy/model/command/test_remove_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 5a5136e

Please sign in to comment.