Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoPascoli committed Oct 8, 2024
1 parent 7bd5059 commit 5ca372c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
5 changes: 3 additions & 2 deletions antarest/study/business/link_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions antarest/study/storage/variantstudy/model/command/create_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
29 changes: 27 additions & 2 deletions tests/integration/study_data_blueprint/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit 5ca372c

Please sign in to comment.