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): add method read_study_api #22

Merged
merged 42 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
bcdf961
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 26, 2024
d31bba1
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 26, 2024
e3c5030
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 27, 2024
e06f118
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 27, 2024
d581ddb
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 27, 2024
2ab7da7
added read_thermal_clusters/storages/renewables methods and realized …
mehdiwahada Nov 27, 2024
6906b17
feat(gh): add release gh action (#14)
MartinBelthle Nov 26, 2024
603cfe7
feat(ci): use tox (#12)
MartinBelthle Nov 26, 2024
ab74da8
chore(release): prepare first release (#15)
MartinBelthle Nov 26, 2024
5b8d269
v0.1.1 (#16)
MartinBelthle Nov 26, 2024
877f53a
integrated integration tests for the reading clusters methods
mehdiwahada Nov 27, 2024
838ae57
Merge branch 'main' into features/add_clusters
mehdiwahada Nov 27, 2024
bb9c9e4
integrated integration tests for the reading clusters methods
mehdiwahada Nov 28, 2024
2dd6b7a
integrated integration tests for the reading clusters methods
mehdiwahada Nov 28, 2024
483e4d6
integrated integration tests for the reading clusters methods
mehdiwahada Nov 28, 2024
d2f4fd9
integrated integration tests for the reading clusters methods
mehdiwahada Nov 28, 2024
6ef393c
adding hydro data (unit and integration testing)
mehdiwahada Nov 28, 2024
ed5aa63
adding hydro data (unit and integration testing)
mehdiwahada Nov 28, 2024
4fcd430
Merge branch 'main' into features/add_hydro_data
mehdiwahada Nov 28, 2024
0e16576
adding hydro data (unit and integration testing)
mehdiwahada Nov 28, 2024
8238314
adding hydro data (unit and integration testing)
mehdiwahada Nov 28, 2024
41821a5
fix(api): correcting import problems
mehdiwahada Nov 29, 2024
e402e5b
fix(api): correcting import problems
mehdiwahada Nov 29, 2024
671336f
fix(api): correcting import problems
mehdiwahada Nov 29, 2024
b56994a
fix(api): correcting import problems
mehdiwahada Nov 29, 2024
d0b8052
feat(api): adding read_study method and unit testing
mehdiwahada Dec 2, 2024
af39424
feat(api): adding read_study method and unit testing
mehdiwahada Dec 2, 2024
0fd3de8
Merge branch 'main' into feat/read_study_api
mehdiwahada Dec 2, 2024
e21278d
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 2, 2024
2bdb548
Merge branch 'main' into feat/read_study_api
MartinBelthle Dec 2, 2024
a7e28fe
Merge remote-tracking branch 'origin/feat/read_study_api' into feat/r…
mehdiwahada Dec 2, 2024
91d01da
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 3, 2024
4c2d927
Merge branch 'main' into feat/read_study_api
MartinBelthle Dec 3, 2024
a729713
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 3, 2024
c4767cf
Merge remote-tracking branch 'origin/feat/read_study_api' into feat/r…
mehdiwahada Dec 3, 2024
7d35ba7
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 3, 2024
e605d28
Merge branch 'main' into feat/read_study_api
MartinBelthle Dec 3, 2024
4b4edd4
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 4, 2024
f6f1a61
Merge remote-tracking branch 'origin/feat/read_study_api' into feat/r…
mehdiwahada Dec 4, 2024
e140264
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 4, 2024
95b08fc
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 4, 2024
78c93c1
feat(api): adding read_study method, unit testing and integration tes…
mehdiwahada Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/antares/model/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ def _directory_not_exists(local_path: Path) -> None:
)


def read_study_api(api_config: APIconf, study_id: str) -> "Study":
session = api_config.set_up_api_conf()
wrapper = RequestWrapper(session)
base_url = f"{api_config.get_host()}/api/v1"
json_study = wrapper.get(f"{base_url}/studies/{study_id}").json()

study_name = json_study.pop("name")
study_version = str(json_study.pop("version"))
json_study.pop("id")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you remove id ?


study_settings = _returns_study_settings(base_url, study_id, wrapper, False, None)
study = Study(study_name, study_version, ServiceFactory(api_config, study_id, study_name), study_settings)

study.read_areas()

return study


class Study:
def __init__(
self,
Expand All @@ -194,6 +212,11 @@ def service(self) -> BaseStudyService:
return self._study_service

def read_areas(self) -> list[Area]:
area_list = self._area_service.read_areas()
MartinBelthle marked this conversation as resolved.
Show resolved Hide resolved
areas = dict()
for area in area_list:
areas.update({area.id: area})

return self._area_service.read_areas()

def get_areas(self) -> MappingProxyType[str, Area]:
Expand Down
39 changes: 38 additions & 1 deletion tests/antares/services/api_services/test_study_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from antares.model.link import Link, LinkProperties, LinkUi
from antares.model.settings.general import GeneralParameters
from antares.model.settings.study_settings import StudySettings
from antares.model.study import Study, create_study_api
from antares.model.study import Study, create_study_api, read_study_api
from antares.service.service_factory import ServiceFactory


Expand Down Expand Up @@ -199,3 +199,40 @@ def test_create_binding_constraint_fails(self):
match=f"Could not create the binding constraint {constraint_name}: {self.antares_web_description_msg}",
):
self.study.create_binding_constraint(name=constraint_name)

def test_read_study_api(self):
base_url = "https://antares.com/api/v1"
url = f"{base_url}/studies/{self.study_id}"
area_url = f"{url}/areas"
json_study = {
MartinBelthle marked this conversation as resolved.
Show resolved Hide resolved
"id": "22c52f44-4c2a-407b-862b-490887f93dd8",
"name": "test_read_areas",
"version": "880",
}

settings = StudySettings()
settings.general_parameters = GeneralParameters(mode="Adequacy")

config_urls = re.compile(f"https://antares.com/api/v1/studies/{self.study_id}/config/.*")

with requests_mock.Mocker() as mocker:
mocker.get(url, json=json_study)
mocker.get(config_urls, json={})
mocker.get(area_url, json={})
Copy link
Contributor

Choose a reason for hiding this comment

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

You could change this to make it return an area to test even further that the created study has an area

actual_study = read_study_api(self.api, self.study_id)

expected_study_name = json_study.pop("name")
expected_study_id = json_study.pop("id")
expected_study_version = json_study.pop("version")
expected_study_settings = StudySettings(**json_study)

expected_study = Study(
expected_study_name,
expected_study_version,
ServiceFactory(self.api, expected_study_id, expected_study_name),
expected_study_settings,
)

assert actual_study.name == expected_study.name
assert actual_study.version == expected_study.version
assert actual_study.service.study_id == expected_study.service.study_id
mehdiwahada marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 7 additions & 1 deletion tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from antares.model.settings.general import GeneralParameters, Mode
from antares.model.settings.study_settings import PlaylistParameters, StudySettings
from antares.model.st_storage import STStorageGroup, STStorageMatrixName, STStorageProperties
from antares.model.study import create_study_api
from antares.model.study import create_study_api, read_study_api
from antares.model.thermal import ThermalClusterGroup, ThermalClusterProperties

from tests.integration.antares_web_desktop import AntaresWebDesktop
Expand All @@ -51,6 +51,12 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):

study = create_study_api("antares-craft-test", "880", api_config)

actual_study = read_study_api(api_config, study.service.study_id)

assert study.service.study_id == actual_study.service.study_id
assert study.name == actual_study.name
assert study.version == actual_study.version
Copy link
Contributor

Choose a reason for hiding this comment

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

You should also test that the 2 studies contain the same areas name. And the same settings (just test some values if the == doesn't work)


# tests area creation with default values
area_name = "FR"
area_fr = study.create_area(area_name)
Expand Down