diff --git a/src/antares/model/area.py b/src/antares/model/area.py index f672a5bf..c1fa814e 100644 --- a/src/antares/model/area.py +++ b/src/antares/model/area.py @@ -282,6 +282,7 @@ def create_renewable_cluster( def create_st_storage(self, st_storage_name: str, properties: Optional[STStorageProperties] = None) -> STStorage: storage = self._area_service.create_st_storage(self.id, st_storage_name, properties) self._st_storages[storage.id] = storage + return storage def get_load_matrix(self) -> pd.DataFrame: @@ -374,3 +375,7 @@ def read_thermal_clusters( ) -> List[ThermalCluster]: return self._thermal_service.read_thermal_clusters(area_id) + def read_hydro( + self, + ) -> Hydro: + return self._area_service.read_hydro(self.id) \ No newline at end of file diff --git a/src/antares/service/api_services/area_api.py b/src/antares/service/api_services/area_api.py index 26c0603f..767b1977 100644 --- a/src/antares/service/api_services/area_api.py +++ b/src/antares/service/api_services/area_api.py @@ -124,6 +124,8 @@ def create_area( ui_response = AreaUiResponse.model_validate(json_ui) ui_properties = AreaUi.model_validate(ui_response.to_craft()) + hydro = self.read_hydro(area_id) + except APIError as e: raise AreaCreationError(area_name, e.message) from e @@ -135,6 +137,7 @@ def create_area( self.renewable_service, properties=area_properties, ui=ui_properties, + hydro=hydro, ) def create_thermal_cluster( @@ -411,7 +414,13 @@ def read_hydro( self, area_id: str, ) -> Hydro: - raise NotImplementedError + url = f"{self._base_url}/studies/{self.study_id}/areas/{area_id}/hydro/form" + json_hydro = self._wrapper.get(url).json() + + hydro_props = HydroProperties(**json_hydro) + hydro = Hydro(self, area_id, hydro_props) + + return hydro def _create_hydro_series(self, area_id: str, matrices: Dict[HydroMatrixName, pd.DataFrame]) -> None: command_body = [] diff --git a/tests/antares/services/api_services/test_area_api.py b/tests/antares/services/api_services/test_area_api.py index f6083b9d..a0cc59d1 100644 --- a/tests/antares/services/api_services/test_area_api.py +++ b/tests/antares/services/api_services/test_area_api.py @@ -342,3 +342,34 @@ def test_read_areas(self): assert actual_thermals[thermal_id].name == expected_area.get_thermals()[thermal_id].name assert actual_renewables[renewable_id].name == expected_area.get_renewables()[renewable_id].name assert actual_storages[storage_id].name == expected_area.get_st_storages()[storage_id].name + + def test_read_hydro(self): + json_hydro = { + "interDailyBreakdown": 1, + "intraDailyModulation": 24, + "interMonthlyBreakdown": 1, + "reservoir": "false", + "reservoirCapacity": 0, + "followLoad": "true", + "useWater": "false", + "hardBounds": "false", + "initializeReservoirDate": 0, + "useHeuristic": "true", + "powerToLevel": "false", + "useLeeway": "false", + "leewayLow": 1, + "leewayUp": 1, + "pumpingEfficiency": 1, + } + url = f"https://antares.com/api/v1/studies/{self.study_id}/areas/{self.area.id}/hydro/form" + + with requests_mock.Mocker() as mocker: + mocker.get(url, json=json_hydro) + hydro_props = HydroProperties(**json_hydro) + + actual_hydro = Hydro(self.api, self.area.id, hydro_props) + expected_hydro = self.area.read_hydro() + + assert actual_hydro.area_id == expected_hydro.area_id + assert actual_hydro.properties == expected_hydro.properties + assert actual_hydro.matrices is None diff --git a/tests/antares/services/api_services/test_study_api.py b/tests/antares/services/api_services/test_study_api.py index 28320762..ad28b749 100644 --- a/tests/antares/services/api_services/test_study_api.py +++ b/tests/antares/services/api_services/test_study_api.py @@ -26,6 +26,7 @@ ) from antares.model.area import Area, AreaProperties, AreaUi from antares.model.binding_constraint import BindingConstraint, BindingConstraintProperties +from antares.model.hydro import HydroProperties from antares.model.link import Link, LinkProperties, LinkUi from antares.model.settings.general import GeneralParameters from antares.model.settings.study_settings import StudySettings @@ -108,9 +109,10 @@ def test_create_area_success(self): } mocker.get(url1, json={area_name: area_ui}, status_code=201) url2 = f"{base_url}/studies/{self.study_id}/areas/{area_name}/properties/form" + url3 = f"{base_url}/studies/{self.study_id}/areas/{area_name}/hydro/form" mocker.put(url2, status_code=201) mocker.get(url2, json=AreaProperties().model_dump(), status_code=200) - + mocker.get(url3, json=HydroProperties().model_dump()) area = self.study.create_area(area_name) assert isinstance(area, Area) diff --git a/tests/integration/test_web_client.py b/tests/integration/test_web_client.py index 6808b029..0dda4366 100644 --- a/tests/integration/test_web_client.py +++ b/tests/integration/test_web_client.py @@ -214,6 +214,11 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop): actual_storage = storage_list[0] assert actual_storage.id == storage_fr.id + # test actual_hydro has the same datas (id, properties and matrices) than area_fr hydro + actual_hydro = area_fr.read_hydro() + assert actual_hydro.area_id == area_fr.id + assert actual_hydro.properties == area_fr.hydro.properties + # test short term storage creation with properties st_storage_name = "wind_onshore" storage_properties = STStorageProperties(reservoir_capacity=0.5)