feat(music-lab): market_trends·trend_reports DB + market.py + /api/music/market 5개 API
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
37
music-lab/tests/test_market.py
Normal file
37
music-lab/tests/test_market.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# music-lab/tests/test_market.py
|
||||
|
||||
def test_ingest_and_report(tmp_db):
|
||||
from app.db import init_db
|
||||
from app.market import ingest_trends, get_suggestions
|
||||
init_db()
|
||||
|
||||
trends = [
|
||||
{"source": "youtube", "country": "BR", "genre": "lo-fi", "keyword": "lofi study", "score": 0.9, "rank": 1, "metadata": {}},
|
||||
{"source": "youtube", "country": "ID", "genre": "pop", "keyword": "pop hits", "score": 0.7, "rank": 2, "metadata": {}},
|
||||
{"source": "billboard", "country": "US", "genre": "pop", "keyword": "top 40", "score": 0.8, "rank": 1, "metadata": {}},
|
||||
]
|
||||
report = ingest_trends(trends, "2026-05-01")
|
||||
assert report["report_date"] == "2026-05-01"
|
||||
assert len(report["top_genres"]) >= 2
|
||||
# pop이 lo-fi보다 score 높아야 함 (2건)
|
||||
genres_by_score = [g["genre"] for g in report["top_genres"]]
|
||||
assert genres_by_score[0] == "pop"
|
||||
|
||||
suggestions = get_suggestions(limit=3)
|
||||
assert len(suggestions) >= 1
|
||||
assert "suno_prompt" in suggestions[0]
|
||||
|
||||
|
||||
def test_ingest_idempotent(tmp_db):
|
||||
"""같은 날 두 번 ingest해도 report가 upsert 돼야 함."""
|
||||
from app.db import init_db, get_trend_reports
|
||||
from app.market import ingest_trends
|
||||
init_db()
|
||||
|
||||
trends = [{"source": "youtube", "country": "BR", "genre": "lo-fi",
|
||||
"keyword": "chill", "score": 0.8, "rank": 1, "metadata": {}}]
|
||||
ingest_trends(trends, "2026-05-01")
|
||||
ingest_trends(trends, "2026-05-01") # 두 번째
|
||||
|
||||
reports = get_trend_reports()
|
||||
assert len([r for r in reports if r["report_date"] == "2026-05-01"]) == 1
|
||||
Reference in New Issue
Block a user