Files
o2o-weather/backend/tests/test_sky_score.py
T
minaChoi 997a366e76 feat: 축제·전시·콘서트·팝업 7일마다 수집, 피드 행사 종류 섞기
- 행사 수집을 화면 요청에서 빼고 worker 가 월 04:00(켤 때 7일 기록 없으면 한 번) 전국 17개 시도를 받는다
- 문화정보원 음악/콘서트(B000) 추가, 쪽·시도 사이 1초 간격으로 초당 요청 제한 회피
- 팝가(popga.co.kr) 팝업스토어 수집: 사이트맵 + 상세 JSON-LD, 바뀐 페이지만 다시 읽음
- 수집이 끝나면 Teams Workflows webhook 으로 종류별 건수 알림 (TEAMS_WEBHOOK_URL)
- event.kind(1=축제 2=전시 3=콘서트 4=팝업) 칸과 종류별 아이콘 추가
- 피드 행사 카드·띠를 축제→팝업→전시→콘서트 차례로 섞음
- 포스트 종류별 내용·피드 기획 문서 갱신

같은 작업 폴더의 다른 작업(외부 API 가드, 노을·달 계산, 각 API, 문서 파일 이름 정리 등)도 함께 담김.
2026-10-07 12:03:48 +09:00

88 lines
3.6 KiB
Python

from datetime import date, datetime, timedelta, timezone
from common.enums import Confidence, SkyGrade, SkyType
from common.utils.geo import destination, haversine_km
from services.calc.sky_score import GRADE_LABEL, Layers, best_times, confidence, grade, reason, score, situation, sunset_timeline, verdict
from services.calc.sun import sun_times
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 == ["해 져요", "가장 붉을 때", "블루아워"]
def test_reason_names_what_decided_the_score():
canvas = Layers(low=0, mid=20, high=50)
assert "알맞게" in reason(canvas, canvas, CLEAR)
assert "먼 하늘" in reason(canvas, canvas, Layers(low=90, mid=50, high=0))
assert "낮은 구름" in reason(Layers(100, 0, 0), Layers(80, 0, 0), CLEAR)
assert "거의 없어" in reason(CLEAR, CLEAR, CLEAR)
def test_verdict_bands_and_gray_label_is_not_weather_word():
assert [verdict(v) for v in (60, 59, 40, 39)] == ["go", "maybe", "maybe", "rest"]
assert GRADE_LABEL[SkyGrade.GRAY] != "흐림"
def test_sunset_timeline_runs_golden_to_blue():
sun = sun_times(date(2026, 10, 6), 37.56, 126.91)
rows = sunset_timeline(sun.golden_start_at, sun.sunset_at, sun.sunset_at + timedelta(minutes=15), sun.dusk_end_at)
assert [r["kind"] for r in rows] == ["golden", "sun", "peak", "blue"]
ats = [datetime.fromisoformat(r["at"]) for r in rows]
assert ats == sorted(ats) and 15 <= (ats[1] - ats[0]).total_seconds() / 60 <= 60
def test_situation_follows_reason_order():
from common.enums import SkySituation
clear, glow = Layers(0, 0, 0), Layers(0, 40, 50)
assert situation(clear, clear, clear) is SkySituation.FEW
assert situation(glow, glow, clear) is SkySituation.GLOW
assert situation(Layers(0, 90, 95), Layers(0, 90, 95), clear) is SkySituation.THICK
assert situation(Layers(80, 0, 0), Layers(70, 0, 0), clear) is SkySituation.LOW_CLOUD
assert situation(glow, glow, Layers(70, 0, 0)) is SkySituation.COVERED
def test_ranking_summary_only_when_most_spots_share_a_situation():
from types import SimpleNamespace
from common.enums import SkySituation
from services.sky_service import ranking_summary
item = lambda s: SimpleNamespace(score=SimpleNamespace(situation=s.value)) # noqa: E731
assert ranking_summary([item(SkySituation.FEW)] * 8 + [item(SkySituation.GLOW)] * 2) == "오늘은 전국이 맑아 대부분 짧게 끝나요"
assert ranking_summary([item(SkySituation.FEW)] * 5 + [item(SkySituation.GLOW)] * 5) is None