Skip to content

Commit 88f5c5b

Browse files
authored
[HNT-1898] Add summary property to hourly forecasts response (#1327)
* [HNT-1898] Add summary property to hourly forecasts response * remove todo comment * minor refactor and new unit test * refactor to bump cache key version and remove try except and unit test * fix lint after rebase
1 parent ec379ba commit 88f5c5b

File tree

8 files changed

+15
-8
lines changed

8 files changed

+15
-8
lines changed

merino/jobs/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
# Include your new jobs module here.
1919

2020
# NOTE: `pretty_exceptions_show_locals` argument is set to False to avoid api_key and secrets exposure.
21-
cli = typer.Typer(
22-
no_args_is_help=True, add_completion=False, pretty_exceptions_show_locals=False
23-
)
21+
cli = typer.Typer(no_args_is_help=True, add_completion=False, pretty_exceptions_show_locals=False)
2422

2523
# Add the wikipedia-indexer subcommands
2624
cli.add_typer(indexer_cmd, no_args_is_help=True)

merino/providers/suggest/weather/backends/accuweather/backend.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,9 @@ def cache_key_for_accuweather_request(
318318
hasher.update(key.encode("utf-8") + value.encode("utf-8"))
319319
extra_identifiers = hasher.hexdigest()
320320

321-
return f"{self.__class__.__name__}:v7:{url}:{extra_identifiers}"
321+
return f"{self.__class__.__name__}:v8:{url}:{extra_identifiers}"
322322

323-
return f"{self.__class__.__name__}:v7:{url}"
323+
return f"{self.__class__.__name__}:v8:{url}"
324324

325325
@functools.cache
326326
def cache_key_template(self, dt: WeatherDataType, language: str) -> str:
@@ -980,6 +980,7 @@ async def _get_hourly_forecasts_from_cache(
980980
if not hourly_forecasts_cached or ttl_cached == REDIS_EXPIRED_KEY_TTL:
981981
return None
982982

983+
# cache hit.
983984
self.metrics_client.increment("accuweather.cache.hit.hourly_forecasts")
984985

985986
# convert binary json from cache to regular json.

merino/providers/suggest/weather/backends/accuweather/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def process_hourly_forecast_response(response: Any) -> dict[str, list[dict[str,
238238
"temperature_unit": temperature_unit,
239239
"temperature_value": temperature_value,
240240
"icon_id": forecast["WeatherIcon"],
241+
"summary": forecast["IconPhrase"],
241242
"url": url,
242243
}
243244
)
@@ -269,6 +270,7 @@ def create_hourly_forecasts_from_json(
269270
epoch_date_time=forecast["epoch_date_time"],
270271
temperature=temperature,
271272
icon_id=forecast["icon_id"],
273+
summary=forecast["summary"],
272274
url=HttpUrl(forecast["url"]),
273275
)
274276

merino/providers/suggest/weather/backends/protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class HourlyForecast(BaseModel):
6262
temperature: Temperature
6363
icon_id: int
6464
url: HttpUrl
65+
summary: str
6566

6667

6768
class HourlyForecastsWithTTL(NamedTuple):

tests/integration/api/v1/weather/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def fixture_hourly_forecasts_with_ttl() -> HourlyForecastsWithTTL:
5454
epoch_date_time=1708281600 + (i * 3600),
5555
temperature=Temperature(f=60 + i),
5656
icon_id=6,
57+
summary="Sunny",
5758
url=HttpUrl(
5859
f"http://www.accuweather.com/en/us/san-francisco/94105/"
5960
f"hourly-weather-forecast/39376?day=1&hbhhour={14+i}&lang=en-us"

tests/integration/providers/suggest/weather/backends/test_accuweather.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def fixture_accuweather_hourly_forecast_response() -> bytes:
347347
"EpochDateTime": base_time + (i * 3600),
348348
"Temperature": {"Unit": "F", "Value": 60 + i},
349349
"WeatherIcon": 6,
350+
"IconPhrase": "Sunny",
350351
"Link": f"http://www.accuweather.com/en/us/san-francisco/94105/hourly-weather-forecast/39376?day=1&hbhhour={hour}&lang=en-us",
351352
}
352353
)

tests/unit/providers/suggest/weather/backends/test_accuweather.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ def fixture_accuweather_hourly_forecast_response() -> bytes:
769769
"EpochDateTime": base_time + (i * 3600),
770770
"Temperature": {"Unit": "F", "Value": 60 + i},
771771
"WeatherIcon": 6,
772+
"IconPhrase": "Sunny",
772773
"Link": f"http://www.accuweather.com/en/us/san-francisco/94105/hourly-weather-forecast/39376?day=1&hbhhour={hour}&lang=en-us",
773774
}
774775
)
@@ -2057,16 +2058,16 @@ async def test_get_forecast_error(accuweather: AccuweatherBackend, language: str
20572058
[
20582059
(
20592060
{"q": "asdfg", "apikey": "filter_me_out"},
2060-
f"AccuweatherBackend:v7:localhost:"
2061+
f"AccuweatherBackend:v8:localhost:"
20612062
f"{hashlib.blake2s('q'.encode('utf-8') + 'asdfg'.encode('utf-8')).hexdigest()}",
20622063
),
20632064
(
20642065
{},
2065-
"AccuweatherBackend:v7:localhost",
2066+
"AccuweatherBackend:v8:localhost",
20662067
),
20672068
(
20682069
{"q": "asdfg"},
2069-
f"AccuweatherBackend:v7:localhost:"
2070+
f"AccuweatherBackend:v8:localhost:"
20702071
f"{hashlib.blake2s('q'.encode('utf-8') + 'asdfg'.encode('utf-8')).hexdigest()}",
20712072
),
20722073
],
@@ -2817,6 +2818,7 @@ async def test_get_hourly_forecasts(
28172818
assert first_forecast.temperature.f == 60
28182819
assert first_forecast.temperature.c == 16
28192820
assert first_forecast.icon_id == 6
2821+
assert first_forecast.summary == "Sunny"
28202822
assert "hourly-weather-forecast/39376?day=1&hbhhour=14" in str(first_forecast.url)
28212823

28222824
metrics_called = [call_arg[0][0] for call_arg in statsd_mock.increment.call_args_list]

tests/unit/providers/suggest/weather/test_provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def fixture_hourly_forecasts_with_ttl() -> HourlyForecastsWithTTL:
252252
epoch_date_time=1708281600,
253253
temperature=Temperature(f=60, c=16),
254254
icon_id=6,
255+
summary="Sunny",
255256
url=HttpUrl(
256257
"http://www.accuweather.com/en/us/san-francisco/94105/"
257258
"hourly-weather-forecast/39376"

0 commit comments

Comments
 (0)