fix(music-lab): market API 타입 강화·ANTHROPIC_API_KEY call-time·HTTP 레이어 테스트 추가
This commit is contained in:
@@ -35,3 +35,65 @@ def test_ingest_idempotent(tmp_db):
|
||||
|
||||
reports = get_trend_reports()
|
||||
assert len([r for r in reports if r["report_date"] == "2026-05-01"]) == 1
|
||||
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_market_endpoints_empty(tmp_db):
|
||||
"""Empty DB: /report/latest returns 404, /suggest returns []."""
|
||||
from app.db import init_db
|
||||
init_db()
|
||||
from app.main import app
|
||||
client = TestClient(app)
|
||||
|
||||
resp = client.get("/api/music/market/report/latest")
|
||||
assert resp.status_code == 404
|
||||
|
||||
resp = client.get("/api/music/market/suggest")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["suggestions"] == []
|
||||
|
||||
|
||||
def test_market_ingest_endpoint(tmp_db):
|
||||
"""POST /ingest returns ok, GET /report/latest returns report, GET /trends returns data."""
|
||||
from app.db import init_db
|
||||
init_db()
|
||||
from app.main import app
|
||||
client = TestClient(app)
|
||||
|
||||
payload = {
|
||||
"trends": [
|
||||
{"source": "youtube", "country": "BR", "genre": "lo-fi",
|
||||
"keyword": "lofi", "score": 0.9, "rank": 1, "metadata": {}},
|
||||
],
|
||||
"report_date": "2026-05-01",
|
||||
}
|
||||
resp = client.post("/api/music/market/ingest", json=payload)
|
||||
assert resp.status_code == 200
|
||||
data = resp.json()
|
||||
assert data["ok"] is True
|
||||
assert data["trends_saved"] == 1
|
||||
assert data["report_date"] == "2026-05-01"
|
||||
|
||||
resp = client.get("/api/music/market/report/latest")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["report_date"] == "2026-05-01"
|
||||
|
||||
resp = client.get("/api/music/market/trends")
|
||||
assert resp.status_code == 200
|
||||
assert len(resp.json()["trends"]) == 1
|
||||
|
||||
|
||||
def test_ingest_empty_trends(tmp_db):
|
||||
"""Empty trends list ingests without error and returns a well-formed report."""
|
||||
from app.db import init_db
|
||||
from app.market import ingest_trends
|
||||
init_db()
|
||||
|
||||
report = ingest_trends([], "2026-05-02")
|
||||
assert report["report_date"] == "2026-05-02"
|
||||
assert report["top_genres"] == []
|
||||
assert report["recommended_styles"] == []
|
||||
assert isinstance(report["insights"], str)
|
||||
assert len(report["insights"]) > 0
|
||||
|
||||
Reference in New Issue
Block a user