feat(라이브): 호스트 간단한 이름과 수정 권한 칩

호스트에 간단한 이름(display_name, 필수)을 추가하고 달력 카드·스케줄표·방송 창에 표시한다.
달력 카드 머리 아래에 그 방송의 틱톡 계정을 작게 보여 준다.
관리자 페이지 칩 live_host_edit 로 호스트 수정을 허용한다. 지우기는 관리자만이고,
개인정보는 페이지에 싣지 않아 빈칸으로 열리며 비워 두면 값이 유지된다.
마이그레이션 004: live_hosts.display_name 추가.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 18:15:30 +09:00
parent 43771edd77
commit e6ebf2188b
19 changed files with 173 additions and 52 deletions
+81 -12
View File
@@ -60,13 +60,14 @@ def _run(code: str, extra_env: dict[str, str] | None = None) -> subprocess.Compl
class StoreTests(unittest.TestCase):
def test_clean_host(self):
got = store.clean_host({"full_name": " Siti Aisyah ", "phone": "+60 12-345 6789", "email": "siti@example.my", "address": "KL",
got = store.clean_host({"display_name": " Siti ", "full_name": " Siti Aisyah ", "phone": "+60 12-345 6789", "email": "siti@example.my", "address": "KL",
"bank_name": "Maybank", "bank_account": "1234-5678", "tiktok_handle": "@siti.live"})
self.assertEqual(got["full_name"], "Siti Aisyah")
self.assertEqual((got["display_name"], got["full_name"]), ("Siti", "Siti Aisyah"))
self.assertNotIn("tiktok_handle", got) # 계정은 방송마다 — 호스트에는 저장 안 함
self.assertEqual(store.clean_host({"full_name": "A"})["phone"], "") # Full Name 만 필수
for bad in ({}, {"full_name": " "}, {"full_name": "A", "email": "nope"}, {"full_name": "A", "phone": "abc"},
{"full_name": "A", "bank_account": "12a"}, {"full_name": "x" * 201}):
self.assertEqual(store.clean_host({"display_name": "A", "full_name": "A"})["phone"], "") # 두 이름만 필수
ok = {"display_name": "A", "full_name": "A"}
for bad in ({}, {"full_name": "A"}, {"display_name": "A"}, {**ok, "full_name": " "}, {**ok, "email": "nope"}, {**ok, "phone": "abc"},
{**ok, "bank_account": "12a"}, {**ok, "full_name": "x" * 201}, {**ok, "display_name": "x" * 51}):
with self.assertRaises(ValueError, msg=bad):
store.clean_host(bad)
@@ -82,7 +83,7 @@ class StoreTests(unittest.TestCase):
"""고치기 창에 계정이 채워져야 저장하면서 지워지지 않는다."""
view = store.broadcast_view({"id": 1, "host_id": 2, "host_name": "Yaya", "tiktok_handle": "alt.acc", "broadcast_date": date(2026, 11, 4),
"start_time": time(20, 0), "end_time": time(22, 0), "venue": "", "sales_amount": None, "images": []})
self.assertEqual((view["tiktok_handle"], view["edit"]["tiktok_handle"], view["label"]), ("alt.acc", "alt.acc", "alt.acc"))
self.assertEqual((view["tiktok_handle"], view["edit"]["tiktok_handle"], view["label"]), ("alt.acc", "alt.acc", "Yaya")) # 카드 머리 = 호스트, 계정은 아래
def test_clean_handle(self):
for raw in ("@siti.live", "siti.live", "https://www.tiktok.com/@siti.live?lang=en", "tiktok.com/@siti.live/video/1"):
@@ -167,7 +168,7 @@ class StoreTests(unittest.TestCase):
self.assertEqual(cal["days"][6]["is_weekend"], True) # 11-07 토
self.assertEqual(cal["days"][0]["roas"], "-") # 광고비 없음
noon = next(s for s in cal["slots"] if s["start"] == "12:00")
self.assertEqual(noon["cells"][3]["cards"][0]["label"], "yaya") # 카드 머리 = Tiktok Handle
self.assertEqual(noon["cells"][3]["cards"][0]["label"], "Yaya") # 카드 머리 = 호스트 간단한 이름
self.assertEqual((noon["cells"][3]["cards"][0]["card_sales"], noon["cells"][3]["cards"][0]["card_commission"], noon["cells"][3]["cards"][0]["card_fee"]),
("48", "4.80", "54.80"))
late = next(s for s in cal["slots"] if s["start"] == "22:00")
@@ -240,9 +241,9 @@ assert "live_host" in MODULE_KEYS and "live_host" in main.MODULE_LABELS
class Fake:
saved = []
def host_choices(self):
return [{"id": 1, "full_name": "Siti", "is_active": True}]
return [{"id": 1, "display_name": "Siti", "full_name": "Siti Binti Awa", "is_active": True}]
def list_hosts(self):
return [{"id": 1, "full_name": "Siti", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank",
return [{"id": 1, "display_name": "Siti", "full_name": "Siti Binti Awa", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank",
"bank_account": "998877", "is_active": True}]
def list_broadcasts(self, start, end):
return []
@@ -257,7 +258,7 @@ class Fake:
fake = main.app.state.live_store = Fake()
adder = U("adder@t.local"); adder["modules"]["live_host"] = True
chip_only = U("chip@t.local", live=False); chip_only["modules"]["live_host"] = True
new = {"full_name": "New Host", "bank_account": "111"}
new = {"display_name": "Newbie", "full_name": "New Host", "bank_account": "111"}
def body(c):
who["u"] = adder
@@ -287,6 +288,74 @@ def body(c):
assert fake.saved[-1] == (1, "New Host", False, "a@t.local"), fake.saved
print("OK")
run(body)
''')
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
self.assertIn("OK", res.stdout)
def test_live_host_edit_chip(self):
"""`live_host_edit` 칩 = 고치기 — 개인정보는 페이지에 없고, 빈칸은 그대로·입력하면 바뀜, 등록·지우기는 안 됨."""
res = _run('''
from app.store import MODULE_KEYS
assert "live_host_edit" in MODULE_KEYS and main.MODULE_LABELS["live_host_edit"] == "라이브 호스트 수정"
OLD = {"id": 1, "display_name": "Siti", "full_name": "Siti Binti Awa", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank",
"bank_account": "998877", "is_active": True}
class Fake:
saved = []
def host_choices(self):
return [{k: OLD[k] for k in ("id", "display_name", "full_name", "is_active")}]
def list_hosts(self):
return [OLD]
def get_host(self, host_id):
return OLD if host_id == 1 else None
def list_broadcasts(self, start, end):
return []
def account_choices(self):
return []
def save_host(self, host_id, values, *, is_active, by):
self.saved.append((host_id, values, is_active))
return 1
def delete_host(self, host_id):
self.saved.append(("deleted", host_id))
fake = main.app.state.live_store = Fake()
editor = U("edit@t.local"); editor["modules"]["live_host_edit"] = True
chip_only = U("chip@t.local", live=False); chip_only["modules"]["live_host_edit"] = True
form = {"id": "1", "display_name": "Nabella", "full_name": "Siti Binti Awa", "is_active": "1"}
def body(c):
who["u"] = editor
assert \'href="/live/settings"\' in c.get("/live/").text
page = c.get("/live/settings").text
for hidden in ("998877", "Maybank", "s@e.my", "/delete", \'id="lv-add"\'):
assert hidden not in page, hidden
assert "data-edit=\'" in page and "Siti Binti Awa" in page and \'name="is_active"\' in page and "data-edit-only" in page
assert c.post("/live/settings/hosts", data=form).json()["ok"]
host_id, values, active = fake.saved[-1]
assert host_id == 1 and active is True and values["display_name"] == "Nabella"
assert (values["bank_account"], values["phone"], values["address"]) == ("998877", "012", "KL") # 빈칸 = 그대로
assert c.post("/live/settings/hosts", data={**form, "bank_account": "111-222"}).json()["ok"]
assert fake.saved[-1][1]["bank_account"] == "111-222" and fake.saved[-1][1]["phone"] == "012" # 입력 = 바뀜
assert c.post("/live/settings/hosts", data={**form, "is_active": ""}).json()["ok"] and fake.saved[-1][2] is False
assert c.post("/live/settings/hosts", data={**form, "id": "9"}).status_code == 400 # 없는 호스트
assert c.post("/live/settings/hosts", data={**form, "display_name": ""}).status_code == 400 # 간단한 이름 필수
count = len(fake.saved)
assert c.post("/live/settings/hosts", data={**form, "id": ""}).status_code == 403 # 등록 권한 없음
assert c.post("/live/settings/hosts/1/delete").status_code == 403
for no_edit in (U("staff@t.local"), chip_only):
who["u"] = no_edit
assert c.get("/live/settings").status_code == 403
assert c.post("/live/settings/hosts", data=form).status_code == 403
assert len(fake.saved) == count
# 관리자는 빈칸 = 지우기 그대로
who["u"] = U("a@t.local", role="admin")
assert c.post("/live/settings/hosts", data=form).json()["ok"] and fake.saved[-1][1]["bank_account"] == ""
print("OK")
run(body)
''')
self.assertEqual(res.returncode, 0, res.stdout + res.stderr)
self.assertIn("OK", res.stdout)
@@ -332,7 +401,7 @@ def jpeg():
return raw.getvalue()
def body(c):
host = {"full_name": NAME, "phone": "+60 12-345", "email": "siti@example.my", "address": "Kuala Lumpur",
host = {"display_name": "S" + tag, "full_name": NAME, "phone": "+60 12-345", "email": "siti@example.my", "address": "Kuala Lumpur",
"bank_name": "Maybank", "bank_account": ACCOUNT, "is_active": "1"}
# ── 호스트 설정 = ERP 관리자만 ──
who["u"] = staff
@@ -397,7 +466,7 @@ def body(c):
c.post("/live/broadcasts", data={**show, "id": bid, "sales_amount": "48", "start_time": "12:00", "end_time": "14:00", "broadcast_date": "2031-03-05"})
cal = c.get("/live/calendar?month=2031-03").text
assert "날짜로 이동" in cal and "토요일" in cal and "12:00 - 14:00" in cal and "2시간 (기본 RM50)" in cal
assert '<span class="lv-card-name">siti.%s</span>' % tag in cal and "RM54.80" in cal and ">4.80</b>" in cal
assert '<span class="lv-card-name">S%s<small>@siti.%s</small></span>' % (tag, tag) in cal and "RM54.80" in cal and ">4.80</b>" in cal
# ── 영문: 화면 세 개 모두 한글 없음(입력한 데이터 제외)·날짜·오류·권한 문구 ──
def no_korean(url):