Skip to content

Commit

Permalink
refactor(bc): rename method in AbstractBindingConstraintCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle committed Jan 23, 2024
1 parent 840d96c commit 9159e4c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
4 changes: 2 additions & 2 deletions antarest/study/business/binding_constraint_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
65 changes: 31 additions & 34 deletions tests/integration/study_data_blueprint/test_binding_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 9159e4c

Please sign in to comment.