diff --git a/antarest/study/business/binding_constraint_management.py b/antarest/study/business/binding_constraint_management.py index 36f3351e6f..c09968c740 100644 --- a/antarest/study/business/binding_constraint_management.py +++ b/antarest/study/business/binding_constraint_management.py @@ -233,7 +233,7 @@ def create_binding_constraint( # Validates the matrices. Needed when the study is a variant because we only append the command to the list if isinstance(study, VariantStudy): - command.fill_matrices(version, True) + command.validates_and_fills_matrices(version, True) file_study = self.storage_service.get_storage(study).get_raw(study) execute_or_add_commands(study, file_study, [command], self.storage_service) @@ -280,7 +280,7 @@ def update_binding_constraint( command = UpdateBindingConstraint(**args) # Validates the matrices. Needed when the study is a variant because we only append the command to the list if isinstance(study, VariantStudy): - command.fill_matrices(study_version, False) + command.validates_and_fills_matrices(study_version, False) execute_or_add_commands(study, file_study, [command], self.storage_service) diff --git a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py index df6800fffb..5a90f0a5b6 100644 --- a/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/create_binding_constraint.py @@ -178,7 +178,7 @@ def get_corresponding_matrices(self, v: Optional[Union[MatrixType, str]], old: b # pragma: no cover raise TypeError(repr(v)) - def fill_matrices(self, version: int, create: bool) -> None: + def validates_and_fills_matrices(self, version: int, create: bool) -> None: if version < 870: self.values = self.get_corresponding_matrices(self.values, old=True, create=create) else: @@ -209,7 +209,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput: binding_constraints = study_data.tree.get(["input", "bindingconstraints", "bindingconstraints"]) new_key = len(binding_constraints) bd_id = transform_name_to_id(self.name) - self.fill_matrices(study_data.config.version, True) + self.validates_and_fills_matrices(study_data.config.version, True) return apply_binding_constraint( study_data, diff --git a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py index 0028b1807b..985734ec7f 100644 --- a/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py +++ b/antarest/study/storage/variantstudy/model/command/update_binding_constraint.py @@ -53,7 +53,7 @@ def _apply(self, study_data: FileStudy) -> CommandOutput: message="Failed to retrieve existing binding constraint", ) - self.fill_matrices(study_data.config.version, False) + self.validates_and_fills_matrices(study_data.config.version, False) return apply_binding_constraint( study_data, diff --git a/tests/integration/study_data_blueprint/test_binding_constraints.py b/tests/integration/study_data_blueprint/test_binding_constraints.py index e6fafbf716..51f477d75a 100644 --- a/tests/integration/study_data_blueprint/test_binding_constraints.py +++ b/tests/integration/study_data_blueprint/test_binding_constraints.py @@ -437,38 +437,35 @@ def test_lifecycle__nominal(self, client: TestClient, user_access_token: str, st assert res.json()["exception"] == "CommandApplicationError" assert res.json()["description"] == "Binding constraint not found" + # todo : add lots of test for v8.7 + def test_for_version_870(self, client: TestClient, admin_access_token: str, study_id: str) -> None: + admin_headers = {"Authorization": f"Bearer {admin_access_token}"} + # Upgrade study to version 870 + res = client.put( + f"/v1/studies/{study_id}/upgrade", + headers=admin_headers, + params={"target_version": 870}, + ) + res.raise_for_status() + task_id = res.json() + task = wait_task_completion(client, admin_access_token, task_id) + from antarest.core.tasks.model import TaskStatus -# todo : add lots of test for v8.7 - - -def test_87(self, client: TestClient, admin_access_token: str, study_id: str) -> None: - admin_headers = {"Authorization": f"Bearer {admin_access_token}"} - # Upgrade study to version 870 - res = client.put( - f"/v1/studies/{study_id}/upgrade", - headers=admin_headers, - params={"target_version": 870}, - ) - res.raise_for_status() - task_id = res.json() - task = wait_task_completion(client, admin_access_token, task_id) - from antarest.core.tasks.model import TaskStatus - - assert task.status == TaskStatus.COMPLETED, task - - # Creation with wrong matrix according to version - res = client.post( - f"/v1/studies/{study_id}/bindingconstraints", - json={ - "name": "binding_constraint_700", - "enabled": True, - "time_step": "hourly", - "operator": "less", - "coeffs": {}, - "comments": "New API", - "values": [[]], - }, - headers=admin_headers, - ) - assert res.status_code == 400 - assert res.json()["description"] == "You cannot fill 'values' as it refers to the matrix before v8.7" + assert task.status == TaskStatus.COMPLETED, task + + # Creation with wrong matrix according to version + res = client.post( + f"/v1/studies/{study_id}/bindingconstraints", + json={ + "name": "binding_constraint_700", + "enabled": True, + "time_step": "hourly", + "operator": "less", + "coeffs": {}, + "comments": "New API", + "values": [[]], + }, + headers=admin_headers, + ) + assert res.status_code == 400 + assert res.json()["description"] == "You cannot fill 'values' as it refers to the matrix before v8.7"