Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): added import_study method to study_api.py #72

Merged
merged 10 commits into from
Feb 5, 2025

Conversation

mehdiwahada
Copy link
Contributor

No description provided.

Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few remarks:

  • The destination_path should be optional if the person just want to import the study. If it's None, we should'nt call the move method
  • The import_study method should be renamed import_study_api and put at the same place as create_study_apias you won't do study.import_study(...), it won't make a lot of sense. This also means the method expects a study_path, and an api_config parameter

@mehdiwahada mehdiwahada marked this pull request as ready for review February 4, 2025 09:32
Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes, otherwise looks good :)

test_path = Path(antares_web.desktop_path.joinpath("internal_studies").joinpath(study.service.study_id))
copy_dir = tmp_path / test_path.name

tmp_path_zip = tmp_path / f"{copy_dir.name}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the f-string:
tmp_path_zip = tmp_path / copy_dir.name

@@ -92,6 +94,26 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
area_fr.create_wind(ts_matrix)
assert area_fr.get_wind_matrix().equals(ts_matrix)

# testing import study
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this test work we should put everthing you wrote here at the end of the test as it would make the test clearer

@@ -92,6 +94,26 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):
area_fr.create_wind(ts_matrix)
assert area_fr.get_wind_matrix().equals(ts_matrix)

# testing import study
test_path = Path(antares_web.desktop_path.joinpath("internal_studies").joinpath(study.service.study_id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a little comment saying why we're doing this weird thing

wrapper = RequestWrapper(session)
base_url = f"{api_config.get_host()}/api/v1"

if has_valid_extension(study_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be clearer to first do a
if not has_valid_extension: raise and then continue what you did without the if.
Also the exception you're raising in this case should be a StudyImportError with the custom message you wrote

base_url = "https://antares.com/api/v1"
url_import = f"{base_url}/studies/_import"
with requests_mock.Mocker() as mocker:
mocker.get(url_import, status_code=404)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need the mock inside this test as we raise before doing any request I believe

"folder": None,
}

json_ui = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need this. you could return an empty json I believe

path_test = Path("/new/test/studies")
imported_study = import_study_api(api_config, zip_study, path_test)

assert imported_study.path == path_test / f"{imported_study.service.study_id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could assert that the imported study has the same areas as the one you copied (to ensure the import went good)

Copy link
Contributor

@MartinBelthle MartinBelthle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small changes

src/antares/craft/model/study.py Outdated Show resolved Hide resolved
tests/antares/services/api_services/test_study_api.py Outdated Show resolved Hide resolved
tests/antares/services/api_services/test_study_api.py Outdated Show resolved Hide resolved
@MartinBelthle MartinBelthle self-requested a review February 5, 2025 17:03
@MartinBelthle MartinBelthle merged commit 081b711 into main Feb 5, 2025
8 checks passed
@MartinBelthle MartinBelthle deleted the feat/add_import_study_api branch February 5, 2025 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants