Skip to content

Commit

Permalink
check create_link from to same area added
Browse files Browse the repository at this point in the history
  • Loading branch information
vargastat committed Dec 11, 2024
1 parent e3b062a commit 946950b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/antares/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ def create_link(
properties: Optional[LinkProperties] = None,
ui: Optional[LinkUi] = None,
) -> Link:
if area_from == area_to:
raise LinkCreationError(area_from, area_to, "A link cannot start and end at the same area")

sorted_areas = sorted([area_from, area_to])
area_from, area_to = sorted_areas

Expand Down
17 changes: 17 additions & 0 deletions tests/antares/services/api_services/test_study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,20 @@ def test_create_link_unknown_area(self):
match=f"Could not create the link {area_from} / {area_to}: {area_to} does not exist",
):
self.study.create_link(area_from=area_from, area_to=area_to)

def test_create_link_same_area(self):
area = "area_1"

self.study._areas[area] = Area(
area,
self.study._area_service,
Mock(),
Mock(),
Mock(),
)

with pytest.raises(
LinkCreationError,
match=f"Could not create the link {area} / {area}: A link cannot start and end at the same area",
):
self.study.create_link(area_from=area, area_to=area)

0 comments on commit 946950b

Please sign in to comment.