Files
o2o-weather/backend/tests/test_season.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

41 lines
1.7 KiB
Python

from datetime import timedelta
import pytest
from httpx import ASGITransport, AsyncClient
import services.season_service as season_service
from common.utils.kma_time import now_kst
from router.router import app
async def _async(v):
return v
@pytest.mark.anyio
async def test_season_week_composes_headline_and_term_progress(monkeypatch):
today = now_kst().date()
past, nxt = today - timedelta(days=5), today + timedelta(days=10)
async def fake_terms(client, year, month):
rows = [{"term_date": past, "name": "추분"}, {"term_date": nxt, "name": "한로"}]
return [r for r in rows if r["term_date"].year == year and r["term_date"].month == month]
monkeypatch.setattr(season_service, "fetch_solar_terms", fake_terms)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
body = (await client.get("/v1/season/week")).json()
assert body["result"]["success"] is True
assert body["term_now"]["name"] == "추분" and body["term_next"]["name"] == "한로"
assert body["headline"].startswith("추분 지나 5일째")
assert body["progress"] == round(5 / 15, 2)
@pytest.mark.anyio
async def test_article_detail_and_not_found():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
listed = (await client.get("/v1/season/article/list")).json()["articles"]
first = (await client.get(f"/v1/season/article/{listed[0]['article_id']}")).json()
missing = (await client.get("/v1/season/article/9999")).json()
assert first["body"] and first["article"]["title"] == listed[0]["title"]
assert missing["result"]["desc"] == "NOT_FOUND"