fix: 오늘 날씨 0~6시가 비면 전날 23시 발표를 다시 받아 채움
This commit is contained in:
1 parent
4ebf1cd894
commit
73294622ad
3 files changed
+58
-6
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
@@ -5,8 +6,10 @@ from httpx import ASGITransport, AsyncClient
|
||||
from sqlalchemy import text
|
||||
|
||||
import services.weather_service as weather_service
|
||||
from common.cache.redis_client import REDIS
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.utils.kma_time import kst_midnight, now_kst
|
||||
from common.utils.kma_time import kst_midnight, latest_vilage_base, now_kst
|
||||
from services.external.kma import day_start_base
|
||||
from router.router import app
|
||||
|
||||
REGION = "1144000000"
|
||||
@@ -32,6 +35,7 @@ async def clean_region():
|
||||
lambda s: s.execute(text(f"DELETE FROM weather_daily WHERE region_code='{REGION}'")),
|
||||
lambda s: s.execute(text(f"DELETE FROM sun_time WHERE region_code='{REGION}'")),
|
||||
])
|
||||
await REDIS.conn.delete(f"vilage0:{REGION}:{now_kst():%Y%m%d}")
|
||||
await wipe()
|
||||
yield
|
||||
await wipe()
|
||||
@@ -106,3 +110,34 @@ def test_slot_view_shows_sunset_only_when_clear():
|
||||
assert _slot_view(at, row(Sky.CLEAR), sun)[0::2] == ("sunset", "노을")
|
||||
assert _slot_view(at, row(Sky.CLOUDY), sun)[0::2] == ("cloud", "흐림")
|
||||
assert _slot_view(at, row(Sky.PARTLY), sun)[0::2] == ("cloud", "구름 많음")
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_today_refetches_midnight_when_first_fetch_missed_it(monkeypatch, clean_region):
|
||||
"""전날 23시 발표 받기가 실패해 0시~ 칸이 비면, 다음 요청 때 그 발표를 다시 받아 채운다."""
|
||||
midnight_base = day_start_base(now_kst().date())
|
||||
if latest_vilage_base(now_kst()) == midnight_base:
|
||||
pytest.skip("최신 발표가 전날 23시면 두 발표가 같다")
|
||||
calls = []
|
||||
fail_midnight = True
|
||||
|
||||
async def fake_fetch(client, nx, ny, base):
|
||||
from services.external.data_go_kr import DataGoKrRequestFailed
|
||||
|
||||
calls.append(base)
|
||||
if base == midnight_base and fail_midnight:
|
||||
raise DataGoKrRequestFailed("timeout")
|
||||
return [it for it in _fake_items(base) if base == midnight_base or it["fcstDate"] + it["fcstTime"] > base.strftime("%Y%m%d%H%M")]
|
||||
|
||||
monkeypatch.setattr(weather_service, "fetch_vilage", fake_fetch)
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
first = (await client.get("/v1/weather/today", params={"region": REGION})).json()
|
||||
assert first["slots"][0].get("temp_c") is None
|
||||
fail_midnight = False
|
||||
await REDIS.conn.delete(f"vilage0:{REGION}:{now_kst():%Y%m%d}")
|
||||
await client.get("/v1/weather/today", params={"region": REGION})
|
||||
await asyncio.gather(*weather_service._background)
|
||||
body = (await client.get("/v1/weather/today", params={"region": REGION})).json()
|
||||
|
||||
assert calls.count(midnight_base) == 2
|
||||
assert body["slots"][0]["temp_c"] == 18
|
||||
Reference in new issue
Block a user