Files
o2o-weather/backend/tests/test_weekend_plan.py
minaChoi ddf05aeb5c feat: 로딩 스켈레톤·행사 사진·전시·주말 예상 점수·노을 탭 재정리 등 화면 전반 개선
- 화면 전체 스켈레톤, 로딩·완료·실패 사이 레이아웃 고정, 값 없음은 '?'
- 행사 사진·출처 표시, 문화정보 API 전시 연결, 행사 30km 거리 기준
- 각 상세 점수 칸 오늘/내일/토/일, 단기예보 밖 주말은 중기예보 예상 점수
- 6각 차트 축 이름을 좋은 방향으로, 계산 근거 문구 정리
- 아이콘 오용·뜻 모를 표시·빈 데이터·포스트 본문 반복 수정
- 미세먼지 별도 포스트, 노을 명소 전국 155곳 거리 기준, 노을 탭 결론 중심 재구성
- 밤 다크 테마·별똥별, 댓글·좋아요 대기·실패 표시
- 주말 전국 랭킹·당일치기 카드, 계절 이야기 사진 수집
- 문서: 포스트 타입별 내용, 각 데이터 정리, TODO 진행 순서
2026-10-06 16:36:11 +09:00

82 lines
3.9 KiB
Python

from datetime import date, datetime
from types import SimpleNamespace
from common.utils.kma_time import KST
from services.week_service import DayPlan, EventItem
from services.weekend_plan import day_plan, forecast, pick_events
SAT, SUN = date(2026, 10, 10), date(2026, 10, 11)
def _day(d: date, lo=12.0, hi=26.0, rainy=False, rain_hours=None, prob=10) -> DayPlan:
weekday = "토" if d.weekday() == 5 else "일"
return DayPlan(day=d, weekday=weekday, holiday=None, icon="rain" if rainy else "sun", temp_min_c=lo, temp_max_c=hi,
headline="", summary="", pick="", rain_hours=rain_hours, is_rainy=rainy, rain_prob=prob)
def _event(name, start, end, dist, image="https://img/x.jpg") -> EventItem:
e = SimpleNamespace(event_id=hash(name), name=name, icon="fireworks", start_date=start, end_date=end, place_name="경기도 고양시 일산동구 호수로 595", image_url=image, source_id="1")
return EventItem(event=e, status="live", status_label="진행 중", fit=None, distance_km=dist)
def test_forecast_both_clear_with_big_gap_warns_about_jacket():
f = forecast([_day(SAT), _day(SUN, lo=13)])
assert f.line.startswith("토·일 둘 다 맑음!")
assert "겉옷" in f.tip and "12°" in f.tip
def test_forecast_one_rainy_day_picks_the_other():
f = forecast([_day(SAT, rainy=True, prob=70), _day(SUN)])
assert f.line.startswith("일요일이 정답!")
assert f.tip == "토요일은 비 70%, 우산 꼭 챙겨요!"
def test_saturday_plan_runs_morning_to_sunset_with_nearest_event():
events = [_event("먼 축제", SAT, SUN, 40.0), _event("가까운 축제", SAT, SUN, 12.0)]
card = day_plan(_day(SAT), datetime(2026, 10, 10, 18, 3, tzinfo=KST), pick_events(SAT, events), 13.0)
assert [s.time for s in card.steps] == ["오전", "오전", "12~16시", "오후", "18:03"]
assert card.steps[1].title == "가까운 축제"
assert card.steps[-1].icon == "sunset"
assert card.eyebrow == "토요일 10.10 · 이렇게 놀아요"
def test_sunday_plan_leads_with_events_ending_today_and_ends_early():
events = [_event("이어지는 축제", SAT, date(2026, 10, 20), 5.0), _event("끝나는 축제", date(2026, 10, 1), SUN, 30.0)]
card = day_plan(_day(SUN), None, pick_events(SUN, events), 13.0)
assert card.line == "끝나는 축제\n오늘이 마지막 날!"
assert card.steps[-1].title == "일찍 귀가 추천" and "13°" in card.steps[-1].sub
assert any(s.title == "끝나는 축제" and s.sub.startswith("오늘이 마지막 날") for s in card.steps)
def test_afternoon_rain_moves_outdoor_time_before_it():
card = day_plan(_day(SAT, rainy=True, rain_hours=(15, 19), prob=60), None, [], None)
assert [s.time for s in card.steps[:2]] == ["~15시", "15~19시"]
assert card.line.startswith("비 오는 토요일")
def test_saturday_ignores_ending_hook_and_sunday_skips_saturday_events():
near = _event("가까운 축제", SAT, SUN, 3.0)
ends_sat = _event("토요일 끝", SAT, SAT, 50.0)
far = _event("먼 축제", SAT, SUN, 40.0)
sat = pick_events(SAT, [ends_sat, near, far])
assert [e.event.name for e in sat] == ["가까운 축제", "먼 축제"]
assert day_plan(_day(SAT), None, sat, None).line.startswith("해 좋은 낮")
assert pick_events(SUN, [near, far], frozenset(e.event.event_id for e in sat)) == []
def test_cloudy_weekend_is_not_called_clear():
cloudy = [_day(SAT), _day(SUN)]
for d in cloudy:
d.icon = "cloud"
f = forecast(cloudy)
assert "맑음" not in f.line
card = day_plan(cloudy[0], None, [], None)
assert all(s.icon != "sun" for s in card.steps) and not card.line.startswith("해 좋은")
def test_event_step_uses_event_icon():
e = _event("가까운 축제", SAT, SUN, 3.0)
e.event.icon = "photo"
card = day_plan(_day(SAT), None, [e], None)
assert next(s for s in card.steps if s.title == "가까운 축제").icon == "photo"