From 5ca372cfd1a4b2feb0e2efd3c9ed876d6a2d8628 Mon Sep 17 00:00:00 2001 From: Theo Pascoli Date: Tue, 8 Oct 2024 10:27:41 +0200 Subject: [PATCH] WIP --- antarest/study/business/link_management.py | 5 ++-- .../variantstudy/model/command/create_link.py | 10 +++++++ .../variantstudy/model/command/update_link.py | 9 +++--- .../study_data_blueprint/test_link.py | 29 +++++++++++++++++-- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/antarest/study/business/link_management.py b/antarest/study/business/link_management.py index f0a3f3beed..063e9a8580 100644 --- a/antarest/study/business/link_management.py +++ b/antarest/study/business/link_management.py @@ -121,8 +121,9 @@ def update_link(self, study: RawStudy, link_creation_info: LinkInfoDTOType) -> L file_study = self.storage_service.get_storage(study).get_raw(study) existing_link = self.get_one_link(study, link_creation_info) - existing_link = existing_link.model_copy(update=link_creation_info.model_dump(exclude={"area1", "area2"}, exclude_none=True)) - # create new object + existing_link = existing_link.model_copy( + update=link_creation_info.model_dump(exclude={"area1", "area2"}, exclude_none=True) + ) command = UpdateLink( area1=link_creation_info.area1, diff --git a/antarest/study/storage/variantstudy/model/command/create_link.py b/antarest/study/storage/variantstudy/model/command/create_link.py index fc52db1a49..7774c2d940 100644 --- a/antarest/study/storage/variantstudy/model/command/create_link.py +++ b/antarest/study/storage/variantstudy/model/command/create_link.py @@ -10,6 +10,7 @@ # # This file is part of the Antares project. import typing as t +from abc import ABCMeta from typing import Any, Dict, List, Optional, Tuple, Union, cast from pydantic import Field, ValidationInfo, field_validator, model_validator @@ -81,6 +82,15 @@ class LinkProperties(LinkInfoProperties820): pass +class AbstractLinkCommand(ICommand, metaclass=ABCMeta): + # area1: str + # area2: str + # parameters: Optional[Dict[str, Any]] = None + # series: Optional[Union[List[List[MatrixData]], str]] = None + # direct: Optional[Union[List[List[MatrixData]], str]] = None + # indirect: Optional[Union[List[List[MatrixData]], str]] = None + pass + class CreateLink(ICommand): """ Command used to create a link between two areas. diff --git a/antarest/study/storage/variantstudy/model/command/update_link.py b/antarest/study/storage/variantstudy/model/command/update_link.py index 8db6977d40..4d0b034e48 100644 --- a/antarest/study/storage/variantstudy/model/command/update_link.py +++ b/antarest/study/storage/variantstudy/model/command/update_link.py @@ -13,9 +13,8 @@ from antarest.study.storage.rawstudy.model.filesystem.config.model import FileStudyTreeConfig from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy -from antarest.study.storage.variantstudy.model.command.common import CommandOutput, CommandName - -from antarest.study.storage.variantstudy.model.command.icommand import ICommand, OutputTuple, MATCH_SIGNATURE_SEPARATOR +from antarest.study.storage.variantstudy.model.command.common import CommandName, CommandOutput +from antarest.study.storage.variantstudy.model.command.icommand import MATCH_SIGNATURE_SEPARATOR, ICommand, OutputTuple from antarest.study.storage.variantstudy.model.model import CommandDTO @@ -65,7 +64,9 @@ def to_dto(self) -> CommandDTO: ) def match_signature(self) -> str: - return str(self.command_name.value + MATCH_SIGNATURE_SEPARATOR + self.area1 + MATCH_SIGNATURE_SEPARATOR + self.area2) + return str( + self.command_name.value + MATCH_SIGNATURE_SEPARATOR + self.area1 + MATCH_SIGNATURE_SEPARATOR + self.area2 + ) def _create_diff(self, other: "ICommand") -> t.List["ICommand"]: pass diff --git a/tests/integration/study_data_blueprint/test_link.py b/tests/integration/study_data_blueprint/test_link.py index 5028d7c2ca..e632a9897f 100644 --- a/tests/integration/study_data_blueprint/test_link.py +++ b/tests/integration/study_data_blueprint/test_link.py @@ -32,10 +32,35 @@ def test_link_update(self, client: TestClient, user_access_token: str, study_typ area1_id = preparer.create_area(study_id, name="Area 1")["id"] area2_id = preparer.create_area(study_id, name="Area 2")["id"] client.post(f"/v1/studies/{study_id}/links", json={"area1": area1_id, "area2": area2_id, "hurdles-cost": True}) - res = client.put(f"/v1/studies/{study_id}/links", json={"area1": area1_id, "area2": area2_id, "hurdles-cost": False, "colorr": 150, "filter-synthesis": "hourly"}) + res = client.put( + f"/v1/studies/{study_id}/links", + json={ + "area1": area1_id, + "area2": area2_id, + "hurdles-cost": False, + "colorr": 150, + "filter-synthesis": "hourly", + }, + ) assert res.status_code == 200 - expected = {'area1': 'area 1', 'area2': 'area 2', 'asset-type': 'ac', 'colorb': 112, 'colorg': 112, 'colorr': 150, 'display-comments': True, 'filter-synthesis': 'hourly', 'filter-year-by-year': 'hourly, daily, weekly, monthly, annual', 'hurdles-cost': False, 'link-style': 'plain', 'link-width': 1.0, 'loop-flow': False, 'transmission-capacities': 'enabled', 'use-phase-shifter': False} + expected = { + "area1": "area 1", + "area2": "area 2", + "asset-type": "ac", + "colorb": 112, + "colorg": 112, + "colorr": 150, + "display-comments": True, + "filter-synthesis": "hourly", + "filter-year-by-year": "hourly, daily, weekly, monthly, annual", + "hurdles-cost": False, + "link-style": "plain", + "link-width": 1.0, + "loop-flow": False, + "transmission-capacities": "enabled", + "use-phase-shifter": False, + } assert expected == res.json() @pytest.mark.parametrize("study_type", ["raw", "variant"])