Skip to content

Commit

Permalink
fix for horizon and read_renewables to return empty list if input mis…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
vargastat committed Feb 4, 2025
1 parent 16eba04 commit 0e5295b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
6 changes: 6 additions & 0 deletions src/antares/craft/service/api_services/renewable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def read_renewables(
self,
area_id: str,
) -> List[RenewableCluster]:
"""
read_renewables will return an error if
study settings renewable_generation_modelling is aggregated
an empty list will be returned instead
"""

url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/clusters/renewable"

try:
Expand Down
18 changes: 0 additions & 18 deletions tests/antares/services/api_services/test_renewable_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,3 @@ def test_read_renewables(self):

assert expected_renewable.id == actual_renewable.id
assert expected_renewable.name == actual_renewable.name

def test_read_renewables_with_404_response_then_return_empty_list(self):
study_id_test = "248bbb99-c909-47b7-b239-01f6f6ae7de7"
area_id = "zone"
url = f"https://antares.com/api/v1/studies/{study_id_test}/areas/{area_id}/"

with requests_mock.Mocker() as mocker:
mocker.get(
url + "clusters/renewable",
status_code=404,
json={"description": "'renewables' not a child of Input", "exception": "ChildNotFoundError"},
)

renewable_api = RenewableApiService(self.api, study_id_test)

actual_renewable_list = renewable_api.read_renewables(area_id)

assert actual_renewable_list == []
6 changes: 1 addition & 5 deletions tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from antares.craft.api_conf.api_conf import APIconf
from antares.craft.exceptions.exceptions import (
APIError,
AreaDeletionError,
BindingConstraintCreationError,
ConstraintMatrixUpdateError,
Expand Down Expand Up @@ -668,7 +667,4 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
study_aggregated = create_study_api("test_aggregated", "880", api_config, new_settings_aggregated)
study_aggregated.create_area("area_without_renewables")
# read_study_api does not raise an error
try:
read_study_api(api_config, study_aggregated.service.study_id)
except APIError as e:
pytest.fail(f"read_study_api raised an unexpected APIError: {e}")
read_study_api(api_config, study_aggregated.service.study_id)

0 comments on commit 0e5295b

Please sign in to comment.