Files
o2o-weather/backend/tests/test_sky_score.py
T
minaChoiandClaude Opus 5.5 e134295ce5 feat: 날씨각 백엔드 API (날씨·노을·지수·주말·계절·피드·로그인·반응)
- 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>
2026-10-02 11:32:22 +09:00

46 lines
1.5 KiB
Python

from datetime import datetime, timezone
from common.enums import Confidence, SkyGrade, SkyType
from common.utils.geo import destination, haversine_km
from services.calc.sky_score import Layers, best_times, confidence, grade, score
CLEAR = Layers(0, 0, 0)
def test_high_clouds_overhead_and_clear_horizon_is_best():
canvas = Layers(low=0, mid=20, high=50)
assert score(canvas, canvas, CLEAR) == 100
def test_clear_sky_is_only_soft():
assert grade(score(CLEAR, CLEAR, CLEAR)) is SkyGrade.SOFT
def test_low_clouds_toward_sun_block_the_light():
canvas = Layers(low=0, mid=20, high=50)
assert grade(score(canvas, canvas, Layers(low=90, mid=50, high=0))) is SkyGrade.GRAY
def test_overcast_low_clouds_is_gray():
gray = Layers(low=100, mid=100, high=100)
assert grade(score(gray, gray, gray)) is SkyGrade.GRAY
def test_confidence_from_model_spread():
assert confidence([70, 72, 68, 71]) is Confidence.HIGH
assert confidence([40, 80, 60, 90]) is Confidence.LOW
assert confidence([70]) is Confidence.LOW
def test_destination_point_is_at_given_distance():
lat, lon = destination(37.56, 126.91, 266, 50)
assert abs(haversine_km(37.56, 126.91, lat, lon) - 50) < 0.1
assert lon < 126.91
def test_sunset_best_times_order():
sunset = datetime(2026, 10, 2, 9, 15, tzinfo=timezone.utc)
dusk = datetime(2026, 10, 2, 9, 41, tzinfo=timezone.utc)
labels = [t["label"] for t in best_times(SkyType.SUNSET, sunset, dusk, 50)]
assert labels == ["해 져요", "가장 붉을 때", "보랏빛 하늘"]