Skip to content

Commit

Permalink
fix(api): fixed minor errors in unit / integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiwahada committed Jan 8, 2025
1 parent 382fdf9 commit b696fff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
31 changes: 21 additions & 10 deletions tests/antares/services/api_services/test_link_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
LinkDownloadError,
LinkPropertiesUpdateError,
LinkUiUpdateError,
LinkUploadError,
LinkUploadError, LinksRetrievalError,
)
from antares.craft.model.area import Area
from antares.craft.model.commons import FilterOption
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_create_indirect_capacity_fail(self):
f"input/links/{self.area_from.id}/capacities/{self.area_to.id}_indirect"
)

mocker.post(raw_url, status_code=404)
mocker.post(raw_url, json={"description": self.antares_web_description_msg}, status_code=404)

with pytest.raises(
LinkUploadError,
Expand All @@ -240,7 +240,7 @@ def test_get_parameters_fail(self):
f"input/links/{self.area_from.id}/{self.area_to.id}_parameters"
)

mocker.get(raw_url, status_code=404)
mocker.get(raw_url, json={"description": self.antares_web_description_msg}, status_code=404)

with pytest.raises(
LinkDownloadError,
Expand All @@ -266,7 +266,7 @@ def test_get_indirect_capacity_fail(self):
f"input/links/{self.area_from.id}/capacities/{self.area_to.id}_indirect"
)

mocker.get(raw_url, status_code=404)
mocker.get(raw_url, json={"description": self.antares_web_description_msg}, status_code=404)

with pytest.raises(
LinkDownloadError,
Expand All @@ -292,7 +292,7 @@ def test_get_direct_capacity_fail(self):
f"input/links/{self.area_from.id}/capacities/{self.area_to.id}_direct"
)

mocker.get(raw_url, status_code=404)
mocker.get(raw_url, json={"description": self.antares_web_description_msg}, status_code=404)

with pytest.raises(
LinkDownloadError,
Expand Down Expand Up @@ -324,10 +324,21 @@ def test_read_links(self, expected_link):
]

with requests_mock.Mocker() as mocker:
expected_link_list = [expected_link]
mocker.get(url_read_links, json=json_links)
actual_link_list = self.study.read_links()
assert len(actual_link_list) == len(expected_link_list)
assert expected_link_list[0].id == actual_link_list[0].id
assert expected_link_list[0].properties == actual_link_list[0].properties
assert expected_link_list[0].ui == actual_link_list[0].ui
assert len(actual_link_list) == 1
actual_link = actual_link_list[0]
assert expected_link.id == actual_link.id
assert expected_link.properties == actual_link.properties
assert expected_link.ui == actual_link.ui

def test_read_links_fail(self):
with requests_mock.Mocker() as mocker:
raw_url = f"https://antares.com/api/v1/studies/{self.study_id}/links"
mocker.get(raw_url, json={"description": self.antares_web_description_msg}, status_code=404)

with pytest.raises(
LinksRetrievalError,
match=f"Could not retrieve links from study {self.study_id} : {self.antares_web_description_msg}"
):
self.study.read_links()
3 changes: 2 additions & 1 deletion tests/integration/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,12 @@ def test_creation_lifecycle(self, antares_web: AntaresWebDesktop):

# assert study got all links
links = study.read_links()
assert len(links) == 2
test_link_be_fr = links[0]
test_link_de_fr = links[1]
assert test_link_be_fr.id == link_be_fr.id
assert test_link_be_fr.properties == link_be_fr.properties
assert test_link_de_fr.id == link_de_fr.id
assert len(links) == 2

# tests renewable properties update
new_props = RenewableClusterProperties()
Expand Down

0 comments on commit b696fff

Please sign in to comment.