feat: 워치 스킨 가운데를 날씨 따라 비구름·천둥 구름·눈구름으로 — 초단기예보 낙뢰(LGT)로 2시간 안 천둥을 워치에 알림
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a74e3b49d0
commit
c0e0363759
10 files changed
+236
-37
No files matched your search
@@ -18,7 +18,7 @@ def test_parse_ultra_reads_rain_and_temp():
|
||||
{"category": c, "fcstDate": "20261002", "fcstTime": "1000", "fcstValue": v}
|
||||
for c, v in [("PTY", "1"), ("RN1", "1mm 미만"), ("T1H", "17")]
|
||||
]
|
||||
assert parse_ultra(items) == [{"at": _kst(2, 10), "rain_type": RainType.RAIN, "rain_mm": 0.5, "temp_c": 17.0}]
|
||||
assert parse_ultra(items) == [{"at": _kst(2, 10), "rain_type": RainType.RAIN, "rain_mm": 0.5, "temp_c": 17.0, "lightning": False}]
|
||||
|
||||
|
||||
def _event(area, var, cmd, tm, seq=1, stress=0):
|
||||
@@ -82,3 +82,13 @@ def test_parse_ultra_reads_drizzle_codes():
|
||||
for c, v in [("PTY", pty), ("RN1", "1mm 미만"), ("T1H", "17")]
|
||||
]
|
||||
assert [p["rain_type"] for p in parse_ultra(items)] == [RainType.RAIN, RainType.SLEET, RainType.SNOW]
|
||||
|
||||
|
||||
def test_parse_ultra_reads_lightning():
|
||||
"""LGT 는 낙뢰(kA). 0 이면 없음, 칸이 없어도 없음."""
|
||||
items = [
|
||||
{"fcstDate": "20261013", "fcstTime": f"{h:02d}00", "category": c, "fcstValue": v}
|
||||
for h, lgt in ((10, "0"), (11, "3"), (12, None))
|
||||
for c, v in [("PTY", "1"), ("RN1", "5.0mm"), ("T1H", "17"), ("LGT", lgt)] if v is not None
|
||||
]
|
||||
assert [p["lightning"] for p in parse_ultra(items)] == [False, True, False]
|
||||
@@ -4,7 +4,9 @@ from types import SimpleNamespace
|
||||
import pytest
|
||||
from httpx import ASGITransport, AsyncClient
|
||||
|
||||
import services.now_service as now_service
|
||||
import services.week_service as week_service
|
||||
from common.cache.redis_client import REDIS
|
||||
from common.utils.kma_time import KST, now_kst
|
||||
from router.router import app
|
||||
from router.v1.watch.watch import timeline
|
||||
@@ -83,3 +85,18 @@ async def test_watch_summary_unknown_region_fails(offline):
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
body = (await client.get("/v1/watch/summary", params={"region": "0000000000"})).json()
|
||||
assert body["result"]["success"] is False
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_watch_summary_flags_thunder_within_2_hours(offline, monkeypatch):
|
||||
start = now_kst().replace(minute=0, second=0, microsecond=0)
|
||||
items = [
|
||||
{"category": c, "fcstDate": (start + timedelta(hours=h)).strftime("%Y%m%d"), "fcstTime": (start + timedelta(hours=h)).strftime("%H%M"), "fcstValue": v}
|
||||
for h in range(1, 7) for c, v in [("PTY", "1"), ("RN1", "5.0mm"), ("T1H", "20"), ("LGT", "2" if h == 1 else "0")]
|
||||
]
|
||||
monkeypatch.setattr(now_service, "fetch_ultra", lambda *a: _async(items))
|
||||
# 앞 테스트가 받아 둔 초단기예보 캐시(비 없음)를 지워야 새 예보를 읽는다
|
||||
await REDIS.conn.delete(f"ultra:{REGION}", f"lock:ultra:{REGION}")
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
body = (await client.get("/v1/watch/summary", params={"region": REGION})).json()
|
||||
assert body["now"]["rain_2h"] is True and body["now"]["thunder"] is True
|
||||
Reference in new issue
Block a user