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>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-10-02 11:32:22 +09:00
1 parent 9cdc0d8fea
commit e134295ce5
135 files changed
+9123

No files matched your search

+65
View File
@@ -0,0 +1,65 @@
import pytest
from httpx import ASGITransport, AsyncClient
from sqlalchemy import text
import services.sky_service as sky_service
from common.cache.redis_client import REDIS
from common.database.db_session_manager import DB_SESSION_MNG
from router.router import app
def _fake_response(points, days):
from datetime import datetime, timedelta
start = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(days=1)
times = [(start + timedelta(hours=h)).strftime("%Y-%m-%dT%H:00") for h in range(24 * (days + 1))]
hourly = {"time": times}
for m in ("ecmwf_ifs025", "gfs_seamless", "jma_seamless", "icon_seamless"):
hourly[f"cloud_cover_low_{m}"] = [0] * len(times)
hourly[f"cloud_cover_mid_{m}"] = [20] * len(times)
hourly[f"cloud_cover_high_{m}"] = [50] * len(times)
return [{"hourly": hourly} for _ in points]
@pytest.fixture
async def clean():
async def wipe():
await DB_SESSION_MNG.execute_lambda_run([
lambda s: s.execute(text("DELETE FROM sky_score")),
lambda s: s.execute(text("DELETE FROM cloud_hourly")),
])
keys = [k async for k in REDIS.conn.scan_iter("sky:*")]
if keys:
await REDIS.conn.delete(*keys)
await wipe()
yield
await wipe()
@pytest.mark.anyio
async def test_sky_view_scores_three_days_with_spots(monkeypatch, clean):
async def fake_fetch(client, points, days=3):
return _fake_response(points, days)
monkeypatch.setattr(sky_service, "fetch_clouds", fake_fetch)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
body = (await client.get("/v1/sky", params={"region": "1144000000"})).json()
assert body["result"]["success"] is True
assert body["sunset"]["grade"] == 4 and body["sunset"]["grade_label"] == "붉음"
assert body["sunset"]["confidence"] == 1
assert len(body["days"]) == 3
assert [s["name"] for s in body["spots"]] == ["망원한강공원", "하늘공원", "선유도공원"]
assert 255 <= body["sunset_azimuth"] <= 280
@pytest.mark.anyio
async def test_sky_ranking_has_30_spots_sorted(monkeypatch, clean):
async def fake_fetch(client, points, days=3):
return _fake_response(points, days)
monkeypatch.setattr(sky_service, "fetch_clouds", fake_fetch)
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
body = (await client.get("/v1/sky/ranking")).json()
scores = [i["score"] for i in body["items"]]
assert len(scores) == 30 and scores == sorted(scores, reverse=True)
assert body["items"][0]["rank"] == 1 and body["items"][0]["note"]