- FastAPI + PostgreSQL + Redis, web·worker 분리, compose 에 backend·worker·postgres·redis 추가 - 기상청 단기·초단기·중기·특보, 에어코리아, Open-Meteo, TourAPI, 특일정보 연동 (첫 조회 때 받고 캐시) - 매일 03:00 worker 가 전국 공통 피드 칸을 정하고 지난 데이터를 정리 - 시드: 시군구 256곳, 지수 23개, 노을 대표 지점·명소, 데이트 명소, 읽을거리 - pytest 66개 (테스트 전용 DB·Redis 사용) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.2 KiB
Python
53 lines
2.2 KiB
Python
from datetime import datetime
|
|
|
|
from common.enums import RainType, Sky
|
|
from common.utils.kma_time import KST, latest_ultra_base, latest_vilage_base
|
|
from services.external.kma import parse_amount, parse_vilage
|
|
|
|
|
|
def _kst(y, mo, d, h, mi=0):
|
|
return datetime(y, mo, d, h, mi, tzinfo=KST)
|
|
|
|
|
|
def test_latest_vilage_base_waits_10_minutes_after_issue():
|
|
assert latest_vilage_base(_kst(2026, 10, 1, 17, 9)) == _kst(2026, 10, 1, 14)
|
|
assert latest_vilage_base(_kst(2026, 10, 1, 17, 10)) == _kst(2026, 10, 1, 17)
|
|
|
|
|
|
def test_latest_vilage_base_before_first_issue_uses_yesterday_23():
|
|
assert latest_vilage_base(_kst(2026, 10, 1, 2, 5)) == _kst(2026, 9, 30, 23)
|
|
|
|
|
|
def test_latest_ultra_base_available_from_45_minutes():
|
|
assert latest_ultra_base(_kst(2026, 10, 1, 10, 44)) == _kst(2026, 10, 1, 9, 30)
|
|
assert latest_ultra_base(_kst(2026, 10, 1, 10, 45)) == _kst(2026, 10, 1, 10, 30)
|
|
|
|
|
|
def test_parse_amount_text():
|
|
assert parse_amount("강수없음") == 0
|
|
assert parse_amount("1mm 미만") == 0.5
|
|
assert parse_amount("1.0mm") == 1.0
|
|
assert parse_amount("30.0~50.0mm") == 30.0
|
|
assert parse_amount("50.0mm 이상") == 50.0
|
|
|
|
|
|
def _item(d, t, cat, val):
|
|
return {"baseDate": "20261001", "baseTime": "1400", "category": cat, "fcstDate": d, "fcstTime": t, "fcstValue": val, "nx": 59, "ny": 127}
|
|
|
|
|
|
def test_parse_vilage_groups_rows_by_hour_and_maps_codes():
|
|
items = [
|
|
_item("20261001", "1500", c, v)
|
|
for c, v in [("TMP", "24"), ("SKY", "3"), ("PTY", "1"), ("POP", "60"), ("PCP", "1mm 미만"), ("REH", "55"), ("WSD", "2.1")]
|
|
] + [_item("20261002", "0600", "TMN", "13.0"), _item("20261002", "1500", "TMX", "23.0")]
|
|
hourly, daily = parse_vilage(items)
|
|
v = hourly[_kst(2026, 10, 1, 15)]
|
|
assert (v["temp_c"], v["sky"], v["rain_type"], v["rain_prob"], v["rain_mm"], v["wind_ms"]) == (24.0, Sky.PARTLY, RainType.RAIN, 60, 0.5, 2.1)
|
|
assert daily[datetime(2026, 10, 2).date()] == {"temp_min_c": 13.0, "temp_max_c": 23.0}
|
|
|
|
|
|
def test_service_key_is_decoded_when_given_encoded():
|
|
from config.settings import Settings
|
|
assert Settings(data_go_kr_service_key="a%2Bb%3D%3D").data_go_kr_service_key == "a+b=="
|
|
assert Settings(data_go_kr_service_key="a+b==").data_go_kr_service_key == "a+b=="
|