diff --git a/tests/variantstudy/model/command/test_create_link.py b/tests/variantstudy/model/command/test_create_link.py index aa147e2df9..95145aac20 100644 --- a/tests/variantstudy/model/command/test_create_link.py +++ b/tests/variantstudy/model/command/test_create_link.py @@ -16,10 +16,11 @@ import numpy as np import pytest from pydantic import ValidationError +from sqlalchemy.orm import Session from antarest.core.exceptions import LinkValidationError from antarest.study.business.link_management import LinkInternal -from antarest.study.model import STUDY_VERSION_8_8 +from antarest.study.model import STUDY_VERSION_8_8, RawStudy from antarest.study.storage.rawstudy.ini_reader import IniReader from antarest.study.storage.rawstudy.model.filesystem.config.model import transform_name_to_id from antarest.study.storage.rawstudy.model.filesystem.factory import FileStudy @@ -57,9 +58,13 @@ def test_validation(self, empty_study: FileStudy, command_context: CommandContex study_version=STUDY_VERSION_8_8, ) - def test_apply(self, empty_study: FileStudy, command_context: CommandContext): + def test_apply(self, empty_study: FileStudy, command_context: CommandContext, db_session: Session): study_version = empty_study.config.version study_path = empty_study.config.study_path + raw_study = RawStudy(id=empty_study.config.study_id, version=str(study_version), path=str(study_path)) + db_session.add(raw_study) + db_session.commit() + area1 = "Area1" area1_id = transform_name_to_id(area1) diff --git a/tests/variantstudy/model/command/test_manage_binding_constraints.py b/tests/variantstudy/model/command/test_manage_binding_constraints.py index 3751c9f865..7268006b41 100644 --- a/tests/variantstudy/model/command/test_manage_binding_constraints.py +++ b/tests/variantstudy/model/command/test_manage_binding_constraints.py @@ -14,8 +14,9 @@ import numpy as np import pytest +from sqlalchemy.orm import Session -from antarest.study.model import STUDY_VERSION_8_8 +from antarest.study.model import STUDY_VERSION_8_8, RawStudy from antarest.study.storage.rawstudy.ini_reader import IniReader from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import ( BindingConstraintFrequency, @@ -232,13 +233,17 @@ def test_manage_binding_constraint(empty_study: FileStudy, command_context: Comm @pytest.mark.parametrize("empty_study", ["empty_study_870.zip"], indirect=True) -def test_scenario_builder(empty_study: FileStudy, command_context: CommandContext): +def test_scenario_builder(empty_study: FileStudy, command_context: CommandContext, db_session: Session): """ Test that the scenario builder is updated when a binding constraint group is renamed or removed """ # This test requires a study with version >= 870, which support "scenarised" binding constraints. study_version = empty_study.config.version assert study_version >= 870 + study_id = empty_study.config.study_id + raw_study = RawStudy(id=study_id, version=str(study_version), path=str(empty_study.config.study_path)) + db_session.add(raw_study) + db_session.commit() # Create two areas and a link between them: areas = {name: transform_name_to_id(name) for name in ["Area X", "Area Y"]} diff --git a/tests/variantstudy/model/command/test_remove_area.py b/tests/variantstudy/model/command/test_remove_area.py index 468b468e69..c3677fb4b9 100644 --- a/tests/variantstudy/model/command/test_remove_area.py +++ b/tests/variantstudy/model/command/test_remove_area.py @@ -12,8 +12,9 @@ import pytest from checksumdir import dirhash +from sqlalchemy.orm import Session -from antarest.study.model import STUDY_VERSION_8_8 +from antarest.study.model import STUDY_VERSION_8_8, RawStudy from antarest.study.storage.rawstudy.model.filesystem.config.binding_constraint import ( BindingConstraintFrequency, BindingConstraintOperator, @@ -79,10 +80,15 @@ def test_remove_with_aggregated(self, empty_study: FileStudy, command_context: C assert output.status, output.message @pytest.mark.parametrize("empty_study", ["empty_study_810.zip", "empty_study_840.zip"], indirect=True) - def test_apply(self, empty_study: FileStudy, command_context: CommandContext): + def test_apply(self, empty_study: FileStudy, command_context: CommandContext, db_session: Session): # noinspection SpellCheckingInspection (empty_study, area_id) = self._set_up(empty_study, command_context) study_version = empty_study.config.version + study_path = empty_study.config.study_path + + raw_study = RawStudy(id=empty_study.config.study_id, version=str(study_version), path=str(study_path)) + db_session.add(raw_study) + db_session.commit() create_district_command = CreateDistrict( name="foo", @@ -111,8 +117,8 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext): ######################################################################################## # Line ending of the `settings/scenariobuilder.dat` must be reset before checksum - reset_line_separator(empty_study.config.study_path.joinpath("settings/scenariobuilder.dat")) - hash_before_removal = dirhash(empty_study.config.study_path, "md5") + reset_line_separator(study_path.joinpath("settings/scenariobuilder.dat")) + hash_before_removal = dirhash(study_path, "md5") empty_study_cfg = empty_study.tree.get(depth=999) if study_version >= 830: @@ -238,7 +244,7 @@ def test_apply(self, empty_study: FileStudy, command_context: CommandContext): ) output = remove_area_command.apply(study_data=empty_study) assert output.status, output.message - assert dirhash(empty_study.config.study_path, "md5") == hash_before_removal + assert dirhash(study_path, "md5") == hash_before_removal actual_cfg = empty_study.tree.get(depth=999) assert actual_cfg == empty_study_cfg