Files
dbx-main/tests/js/render_live.py
T
king ecc76ae4d8 feat(라이브): 방송 창에 Fee·커미션 자동 계산, 광고비·호스트 비용 입력, 방송 장소 뺌
- Fee = 시간 x RM25, 커미션 = 판매금액 x 10% (저장 안 함, 이미지에서 매출을 읽으면 다시 계산)
- 광고비·호스트 비용(수기) = 방송마다 저장 (마이그레이션 live_db_006_broadcast_fees.sql)
- 달력 날짜 광고비 = 그날 방송 광고비 합, 호스트 비용 = host_fee 합 (날짜별 광고비 입력 버튼·/live/ad-spend 없앰)
- 방송 장소는 창·표에서 뺌 (예전 값은 DB 에 그대로)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 15:16:32 +09:00

69 lines
3.5 KiB
Python

"""라이브 커머스 달력 보기를 진짜 앱 라우터로 렌더 — 오른쪽 달력 브라우저 테스트용(2026-11-05).
python tests/js/render_live.py # → tests/js/.out/live_cal_ko.html · live_cal_en.html · live_cal_dec.html
DB 없이 가짜 저장소로 11월·12월 화면을 그린다(공휴일 = 실제 표).
"""
from __future__ import annotations
import os
import sys
import tempfile
from datetime import date, time
from decimal import Decimal
from unittest.mock import patch
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, ROOT)
os.chdir(ROOT)
OUT_DIR = os.path.join(ROOT, "tests", "js", ".out")
for key in ("ASSET", "CAFE24", "CUPANG", "VACATION", "PROJECT", "DISPATCH", "PERFORMANCE", "MALAYSIA_STOCK", "ITEMCODE", "EXPENSE", "INOUT", "OUTREACH", "LIVE"):
os.environ[key + "_DB_URL"] = ""
os.environ.update(SESSION_SECRET_KEY="local-live-test-only", SESSION_COOKIE_SECURE="false", PERFORMANCE_AUTO_SYNC="false", DATA_DIR=tempfile.mkdtemp())
from fastapi.testclient import TestClient # noqa: E402
import app.main as main # noqa: E402
class Fake:
def host_choices(self):
return [{"id": 1, "display_name": "Nabella", "full_name": "Nazzureen Nabella binti Samad", "is_active": True}]
def list_broadcasts(self, start, end):
if start.month != 11:
return []
# 운영 화면처럼 — 6·8·16시 칸에 카드(세 줄 모두 카드가 있으면 그 줄이 가장 높다), 모든 시간 칸을 채워 높이 최악으로
return [{"id": h, "host_id": 1, "host_name": "Nabella", "tiktok_handle": "MainAccount", "broadcast_date": date(2026, 11, 5), "start_time": time(h),
"end_time": time(h + 2), "venue": "", "sales_amount": Decimal("500"), "ad_spend": Decimal("100"), "host_fee": Decimal("50"),
"images": [{"id": 7, "filename": "r.png"}, {"id": 8, "filename": "s.png"}] if h == 6 else []} for h in range(6, 24, 2) if h < 22] + \
[{"id": 22, "host_id": 1, "host_name": "Nabella", "tiktok_handle": "MainAccount", "broadcast_date": date(2026, 11, 5), "start_time": time(22),
"end_time": time(23, 30), "venue": "", "sales_amount": Decimal("500"), "ad_spend": None, "host_fee": None, "images": []}]
def broadcast_days(self, start, end):
return ["2026-10-30", "2026-11-05", "2026-11-20", "2026-12-03"] # 오른쪽 달력 점 — 다른 달 날짜도
def account_choices(self):
return ["MainAccount"]
def main_() -> None:
os.makedirs(OUT_DIR, exist_ok=True)
main.app.state.live_store = Fake()
user = {"email": "t@test.local", "name": "T", "role": "user", "is_super_admin": False, "modules": {"live": True}}
with patch.object(main, "get_current_user_record", side_effect=lambda r: user), patch.object(main, "get_session_user", side_effect=lambda r: user), \
patch.object(main.user_store, "get", side_effect=lambda e: user), patch.object(main.user_store, "list_all", side_effect=lambda: [user]):
for name, lang, month in (("live_cal_ko.html", "ko", "2026-11"), ("live_cal_en.html", "en", "2026-11"), ("live_cal_dec.html", "ko", "2026-12")):
client = TestClient(main.app)
client.cookies.set("live_lang", lang)
res = client.get("/live/calendar?month=" + month)
assert res.status_code == 200, (name, res.status_code)
with open(os.path.join(OUT_DIR, name), "w", encoding="utf-8") as f:
f.write(res.text)
print("ok")
if __name__ == "__main__":
main_()