From e140264b1339307cb3890506e361c485514f8079 Mon Sep 17 00:00:00 2001 From: wahadameh Date: Wed, 4 Dec 2024 14:27:55 +0100 Subject: [PATCH] feat(api): adding read_study method, unit testing and integration testing of the method --- .../services/api_services/test_study_api.py | 57 ++----------------- tests/integration/test_web_client.py | 15 +++-- 2 files changed, 13 insertions(+), 59 deletions(-) diff --git a/tests/antares/services/api_services/test_study_api.py b/tests/antares/services/api_services/test_study_api.py index 05168b1d..98c7cc96 100644 --- a/tests/antares/services/api_services/test_study_api.py +++ b/tests/antares/services/api_services/test_study_api.py @@ -216,55 +216,6 @@ def test_read_study_api(self): } } - json_thermal = [ - { - "id": "therm_un", - "group": "Gas", - "name": "therm_un", - "enabled": "true", - "unitCount": 1, - "nominalCapacity": 0, - } - ] - - json_renewable = [ - { - "id": "test_renouvelable", - "group": "Solar Thermal", - "name": "test_renouvelable", - "enabled": "true", - "unitCount": 1, - "nominalCapacity": 0, - "tsInterpretation": "power-generation", - } - ] - - json_st_storage = [ - { - "id": "test_storage", - "group": "Pondage", - "name": "test_storage", - "injectionNominalCapacity": 0, - "withdrawalNominalCapacity": 0, - "reservoirCapacity": 0, - "efficiency": 1, - "initialLevel": 0.5, - "initialLevelOptim": "false", - "enabled": "true", - } - ] - - json_properties = { - "energyCostUnsupplied": 0, - "energyCostSpilled": 0, - "nonDispatchPower": "true", - "dispatchHydroPower": "true", - "otherDispatchPower": "true", - "filterSynthesis": ["weekly", "daily", "hourly", "monthly", "annual"], - "filterByYear": ["weekly", "daily", "hourly", "monthly", "annual"], - "adequacyPatchMode": "outside", - } - config_urls = re.compile(f"https://antares.com/api/v1/studies/{self.study_id}/config/.*") base_url = "https://antares.com/api/v1" @@ -279,10 +230,10 @@ def test_read_study_api(self): mocker.get(url, json=json_study) mocker.get(config_urls, json={}) mocker.get(area_url, json=json_ui) - mocker.get(area_props_url, json=json_properties) - mocker.get(renewable_url, json=json_renewable) - mocker.get(thermal_url, json=json_thermal) - mocker.get(storage_url, json=json_st_storage) + mocker.get(area_props_url, json={}) + mocker.get(renewable_url, json=[]) + mocker.get(thermal_url, json=[]) + mocker.get(storage_url, json=[]) actual_study = read_study_api(self.api, self.study_id) expected_study_name = json_study.pop("name") diff --git a/tests/integration/test_web_client.py b/tests/integration/test_web_client.py index 6e9807eb..a2ad9336 100644 --- a/tests/integration/test_web_client.py +++ b/tests/integration/test_web_client.py @@ -226,17 +226,20 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop): assert study.name == actual_study.name assert study.version == actual_study.version assert list(study.get_areas().keys()) == list(actual_study.get_areas().keys()) + + expected_area_fr = study.get_areas()["fr"] + actual_area_fr = actual_study.get_areas()["fr"] + assert ( + list(expected_area_fr.get_thermals()) == list(actual_area_fr.get_thermals()) + ) assert ( - study.get_areas()["fr"].get_thermals().get("cluster_test").id - == actual_study.get_areas()["fr"].get_thermals().get("cluster_test").id + list(expected_area_fr.get_renewables()) == list(actual_area_fr.get_renewables()) ) assert ( - study.get_areas()["fr"].get_renewables().get("cluster_test").id - == actual_study.get_areas()["fr"].get_renewables().get("cluster_test").id + list(expected_area_fr.get_st_storages()) == list(actual_area_fr.get_st_storages()) ) assert ( - study.get_areas()["fr"].get_st_storages().get("cluster_test").id - == actual_study.get_areas()["fr"].get_st_storages().get("cluster_test").id + list(study.get_settings()) == list(actual_study.get_settings()) ) # test short term storage creation with properties