Skip to content

Commit

Permalink
fix 502 error
Browse files Browse the repository at this point in the history
  • Loading branch information
François AIZPURU committed Nov 15, 2023
1 parent 2dfa3de commit 534e53f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
13 changes: 7 additions & 6 deletions src/meteofrance_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,18 @@ def get_warning_current_phenomenoms(
# Send the API request
resp = self.session.request(
"get",
"warning/currentphenomenons",
"v3/warning/currentphenomenons",
params={"domain": domain, "depth": depth},
)

# Create object with API response
phenomenoms = CurrentPhenomenons(resp.json())

# if user ask to have the coastal bulletin merged
if with_costal_bulletin:
if domain in COASTAL_DEPARTMENT_LIST:
resp = self.session.request(
"get",
"warning/currentphenomenons",
"v3/warning/currentphenomenons",
params={"domain": domain + "10"},
)
phenomenoms.merge_with_coastal_phenomenons(
Expand Down Expand Up @@ -272,7 +271,9 @@ def get_warning_full(self, domain: str, with_costal_bulletin: bool = False) -> F
# TODO: add formatDate parameter

# Send the API request
resp = self.session.request("get", "warning/full", params={"domain": domain})
resp = self.session.request(
"get", "/v3/warning/full", params={"domain": domain}
)

# Create object with API response
full_phenomenoms = Full(resp.json())
Expand All @@ -282,7 +283,7 @@ def get_warning_full(self, domain: str, with_costal_bulletin: bool = False) -> F
if domain in COASTAL_DEPARTMENT_LIST:
resp = self.session.request(
"get",
"warning/full",
"v3/warning/full",
params={"domain": domain + "10"},
)
full_phenomenoms.merge_with_coastal_phenomenons(Full(resp.json()))
Expand All @@ -301,7 +302,7 @@ def get_warning_thumbnail(self, domain: str = "france") -> str:
"""
# Return directly the URL of the gif image
return (
f"{METEOFRANCE_API_URL}/warning/thumbnail?&token={METEOFRANCE_API_TOKEN}"
f"{METEOFRANCE_API_URL}/v3/warning/thumbnail?&token={METEOFRANCE_API_TOKEN}"
f"&domain={domain}"
)

Expand Down
24 changes: 10 additions & 14 deletions tests/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
WARNING_COLOR_LIST = [1, 2, 3, 4]


@pytest.mark.skip(reason="Returns 502 Server Error: Bad Gateway from summer 2023")
def test_currentphenomenons(requests_mock: Mock) -> None:
"""Test basic weather alert results from API."""
client = MeteoFranceClient()

requests_mock.request(
"get",
f"{METEOFRANCE_API_URL}/warning/currentphenomenons",
f"{METEOFRANCE_API_URL}/v3/warning/currentphenomenons",
json={
"update_time": 1591279200,
"end_validity_time": 1591365600,
Expand All @@ -35,23 +34,22 @@ def test_currentphenomenons(requests_mock: Mock) -> None:

current_phenomenoms = client.get_warning_current_phenomenoms(domain="32", depth=1)

assert type(current_phenomenoms.update_time) == int
assert type(current_phenomenoms.end_validity_time) == int
assert type(current_phenomenoms.domain_id) == str
assert isinstance(current_phenomenoms.update_time, int)
assert isinstance(current_phenomenoms.end_validity_time, int)
assert isinstance(current_phenomenoms.domain_id, str)
assert "phenomenon_id" in current_phenomenoms.phenomenons_max_colors[0].keys()
assert current_phenomenoms.get_domain_max_color() == 3


@pytest.mark.skip(reason="Returns 502 Server Error: Bad Gateway from summer 2023")
def test_fulls() -> None:
"""Test advanced weather alert results from API."""
client = MeteoFranceClient()

warning_full = client.get_warning_full(domain="31")

assert type(warning_full.update_time) == int
assert type(warning_full.end_validity_time) == int
assert type(warning_full.domain_id) == str
assert isinstance(warning_full.update_time, int)
assert isinstance(warning_full.end_validity_time, int)
assert isinstance(warning_full.domain_id, str)
assert warning_full.domain_id == "31"
assert warning_full.color_max in WARNING_COLOR_LIST
assert (
Expand All @@ -70,13 +68,12 @@ def test_thumbnail() -> None:
thumbnail_url = client.get_warning_thumbnail()

assert thumbnail_url == (
"https://webservice.meteofrance.com/warning/thumbnail"
"https://webservice.meteofrance.com/v3/warning/thumbnail"
"?&token=__Wj7dVSTjV9YGu1guveLyDq0g7S7TfTjaHBTPTpO0kj8__&"
"domain=france"
)


@pytest.mark.skip(reason="Returns 502 Server Error: Bad Gateway from summer 2023")
@pytest.mark.parametrize("dep, res", [("13", True), ("32", False)])
def test_currentphenomenons_with_coastal_bulletin(dep: str, res: bool) -> None:
"""Test getting a complete basic bulletin for coastal department."""
Expand All @@ -86,13 +83,12 @@ def test_currentphenomenons_with_coastal_bulletin(dep: str, res: bool) -> None:
domain=dep, depth=1, with_costal_bulletin=True
)
has_coastal_phenomenom = any(
phenomenom["phenomenon_id"] == 9
phenomenom["phenomenon_id"] == "9"
for phenomenom in current_phenomenoms.phenomenons_max_colors
)
assert has_coastal_phenomenom == res


@pytest.mark.skip(reason="Returns 502 Server Error: Bad Gateway from summer 2023")
@pytest.mark.parametrize("dep, res", [("13", True), ("32", False)])
def test_full_with_coastal_bulletint(dep: str, res: bool) -> None:
"""Test getting a complete advanced bulletin for coastal department."""
Expand All @@ -101,7 +97,7 @@ def test_full_with_coastal_bulletint(dep: str, res: bool) -> None:
full_phenomenoms = client.get_warning_full(domain=dep, with_costal_bulletin=True)

has_coastal_phenomenom = any(
phenomenom["phenomenon_id"] == 9
phenomenom["phenomenon_id"] == "9"
for phenomenom in full_phenomenoms.phenomenons_items
)
assert has_coastal_phenomenom == res

0 comments on commit 534e53f

Please sign in to comment.