Skip to content

Commit

Permalink
feat(api): change attribute in move and complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
salemsd committed Jan 13, 2025
1 parent 215620b commit 7995725
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/antares/craft/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def delete_output(self, output_name: str) -> None:

def move(self, destination_folder: Path) -> None:
self._study_service.move_study(destination_folder)
self.path = PurePath(destination_folder) / f"{self.service.study_id}"


def _verify_study_already_exists(study_directory: Path) -> None:
Expand Down
18 changes: 18 additions & 0 deletions tests/antares/services/api_services/test_study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from io import StringIO
from json import dumps
from pathlib import Path, PurePath
from unittest.mock import Mock, patch

import pandas as pd
Expand All @@ -31,6 +32,7 @@
SimulationFailedError,
SimulationTimeOutError,
StudyCreationError,
StudyMoveError,
StudySettingsUpdateError,
StudyVariantCreationError,
)
Expand Down Expand Up @@ -673,3 +675,19 @@ def test_delete_outputs(self):
mocker.get(outputs_url, json={"description": error_message}, status_code=404)
with pytest.raises(OutputsRetrievalError, match=error_message):
self.study.delete_outputs()

def test_move_study(self):
new_path = Path("/new/path/test")
with requests_mock.Mocker() as mocker:
move_url = f"https://antares.com/api/v1/studies/{self.study_id}/move?folder_dest={new_path}"
mocker.put(move_url, status_code=200)

assert self.study.path == PurePath(".")
self.study.move(new_path)
assert self.study.path == PurePath(new_path) / f"{self.study_id}"

# Failing
error_message = "Study move failed"
mocker.put(move_url, json={"description": error_message}, status_code=404)
with pytest.raises(StudyMoveError, match=error_message):
self.study.move(new_path)
13 changes: 13 additions & 0 deletions tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# This file is part of the Antares project.
import pytest

from pathlib import Path, PurePath

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -608,3 +610,14 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
study.delete_outputs()
assert len(study.get_outputs()) == 0
assert len(study.read_outputs()) == 0

# ===== Test study moving =====

new_path = Path("/new/path/test")
assert study.path == PurePath(".")
study.move(new_path)
assert study.path == PurePath(new_path) / f"{study.service.study_id}"

moved_study = read_study_api(api_config, study.service.study_id)
assert moved_study.path == study.path
assert moved_study.name == study.name

0 comments on commit 7995725

Please sign in to comment.