From e8f9538c7cf60573e6192aa630c3a82fb0dd86ab Mon Sep 17 00:00:00 2001 From: Sigurd Borge Date: Tue, 10 Dec 2024 15:59:38 +0100 Subject: [PATCH] Study creation with settings, also updated playlist parameters to validate on assignment. --- src/antares/model/settings/playlist_parameters.py | 3 +++ tests/integration/test_local_client.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/antares/model/settings/playlist_parameters.py b/src/antares/model/settings/playlist_parameters.py index 1ed33b07..95acc96f 100644 --- a/src/antares/model/settings/playlist_parameters.py +++ b/src/antares/model/settings/playlist_parameters.py @@ -28,6 +28,9 @@ class PlaylistParameters(BaseModel): playlist (list[PlaylistData]): A list of years (in **PlaylistData** format) in the playlist """ + class Config: + validate_assignment = True + playlist: list[PlaylistData] = Field(default=[], exclude=True) _playlist_dict_error_msg = "Not a valid playlist dictionary." diff --git a/tests/integration/test_local_client.py b/tests/integration/test_local_client.py index 25b1350c..70f779e1 100644 --- a/tests/integration/test_local_client.py +++ b/tests/integration/test_local_client.py @@ -27,6 +27,9 @@ from antares.model.commons import FilterOption from antares.model.link import Link, LinkProperties, LinkUi from antares.model.renewable import RenewableClusterGroup, RenewableClusterProperties +from antares.model.settings.general import GeneralParametersLocal, Mode +from antares.model.settings.playlist_parameters import PlaylistParameters +from antares.model.settings.study_settings import StudySettingsLocal from antares.model.st_storage import STStorageGroup, STStorageProperties from antares.model.study import Study from antares.model.thermal import ThermalCluster, ThermalClusterGroup, ThermalClusterProperties @@ -262,3 +265,15 @@ def test_local_study(self, tmp_path, other_area): constraint_2.id: constraint_2, constraint_3.id: constraint_3, } + + # test study creation with settings + settings = StudySettingsLocal() + settings.general_parameters = GeneralParametersLocal(mode="Adequacy") + settings.general_parameters.year_by_year = False + settings.playlist_parameters = PlaylistParameters() + settings.playlist_parameters.playlist = [{"status": False, "weight": 1}] + new_study = create_study_local("second_study", "880", tmp_path, settings) + settings = new_study.get_settings() + assert settings.general_parameters.mode == Mode.ADEQUACY.value + assert not settings.general_parameters.year_by_year + assert settings.playlist_parameters.model_dump() == {1: {"status": False, "weight": 1}}