feat(music-lab): video_projects·revenue_records DB 마이그레이션 + CRUD
- init_db()에 video_projects, revenue_records 테이블 추가 (CREATE IF NOT EXISTS) - video_projects CRUD: create/get/get_all/update_status/delete + get_track_by_id - revenue_records CRUD: create/get_all/update/delete/get_revenue_dashboard (RPM 자동 계산) - TDD: tests/test_db_video.py 5개 테스트 모두 PASSED - pytest.ini 추가 (pythonpath=. 설정) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
72
music-lab/tests/test_db_video.py
Normal file
72
music-lab/tests/test_db_video.py
Normal file
@@ -0,0 +1,72 @@
|
||||
def test_create_and_get_video_project(tmp_db):
|
||||
from app.db import init_db, create_video_project, get_video_project
|
||||
init_db()
|
||||
proj = create_video_project({"track_id": 1, "format": "visualizer", "target_countries": ["BR", "ID"]})
|
||||
assert proj["id"] == 1
|
||||
assert proj["format"] == "visualizer"
|
||||
assert proj["status"] == "pending"
|
||||
assert "BR" in proj["target_countries"]
|
||||
|
||||
fetched = get_video_project(1)
|
||||
assert fetched["id"] == 1
|
||||
assert fetched["track_id"] == 1
|
||||
|
||||
|
||||
def test_update_video_project_status(tmp_db):
|
||||
from app.db import init_db, create_video_project, update_video_project_status, get_video_project
|
||||
init_db()
|
||||
create_video_project({"track_id": 2, "format": "slideshow"})
|
||||
update_video_project_status(
|
||||
1, "done",
|
||||
output_path="/data/videos/1/output.mp4",
|
||||
output_url="/media/videos/1/output.mp4",
|
||||
thumbnail_path="/data/videos/1/thumbnail.jpg",
|
||||
yt_title="Chill Beats Brazil",
|
||||
yt_description="relaxing lofi",
|
||||
yt_tags=["lofi", "chill"],
|
||||
)
|
||||
proj = get_video_project(1)
|
||||
assert proj["status"] == "done"
|
||||
assert proj["yt_title"] == "Chill Beats Brazil"
|
||||
assert "lofi" in proj["yt_tags"]
|
||||
assert proj["completed_at"] is not None
|
||||
|
||||
|
||||
def test_delete_video_project(tmp_db):
|
||||
from app.db import init_db, create_video_project, delete_video_project, get_video_project
|
||||
init_db()
|
||||
create_video_project({"track_id": 1, "format": "visualizer"})
|
||||
assert delete_video_project(1) is True
|
||||
assert get_video_project(1) is None
|
||||
assert delete_video_project(99) is False
|
||||
|
||||
|
||||
def test_create_revenue_record(tmp_db):
|
||||
from app.db import init_db, create_revenue_record, get_all_revenue_records
|
||||
import pytest
|
||||
init_db()
|
||||
rec = create_revenue_record({
|
||||
"yt_video_id": "abc123",
|
||||
"record_month": "2026-04",
|
||||
"views": 10000,
|
||||
"watch_hours": 500.0,
|
||||
"revenue_usd": 25.0,
|
||||
"country": "BR",
|
||||
})
|
||||
assert rec["id"] == 1
|
||||
assert rec["rpm_usd"] == pytest.approx(2.5)
|
||||
|
||||
records = get_all_revenue_records(yt_video_id="abc123")
|
||||
assert len(records) == 1
|
||||
|
||||
|
||||
def test_revenue_dashboard(tmp_db):
|
||||
from app.db import init_db, create_revenue_record, get_revenue_dashboard
|
||||
import pytest
|
||||
init_db()
|
||||
create_revenue_record({"yt_video_id": "v1", "record_month": "2026-04", "views": 5000, "revenue_usd": 10.0})
|
||||
create_revenue_record({"yt_video_id": "v2", "record_month": "2026-04", "views": 5000, "revenue_usd": 15.0})
|
||||
dash = get_revenue_dashboard()
|
||||
assert dash["total_revenue_usd"] == pytest.approx(25.0)
|
||||
assert dash["total_views"] == 10000
|
||||
assert len(dash["by_month"]) == 1
|
||||
Reference in New Issue
Block a user