feat(라이브): 호스트 쇼핑몰(틱톡·쇼피) 선택·로고, 목록 사용 토글

- 호스트 창 맨 위 라디오 + 로고(안 고르면 흑백, 고르면 컬러, 같은 크기), 저장 때 필수
- 호스트 목록 첫 열에 쇼핑몰 로고, 상태 열은 고치기 권한자에게 토글(바로 저장)
- live_db 005: live_hosts.platform 열 추가
- 낡은 테스트 검사(Jump to Date, 호스트 Tiktok Handle) 정리

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 10:26:56 +09:00
parent 02f83947de
commit de294a53a4
15 changed files with 136 additions and 33 deletions
+32 -15
View File
@@ -60,13 +60,13 @@ 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({"display_name": " Siti ", "full_name": " Siti Aisyah ", "phone": "+60 12-345 6789", "email": "siti@example.my", "address": "KL",
got = store.clean_host({"platform": "TikTok", "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["display_name"], got["full_name"]), ("Siti", "Siti Aisyah"))
self.assertEqual((got["platform"], got["display_name"], got["full_name"]), ("tiktok", "Siti", "Siti Aisyah"))
self.assertNotIn("tiktok_handle", got) # 계정은 방송마다 — 호스트에는 저장 안 함
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 = {"platform": "shopee", "display_name": "A", "full_name": "A"}
self.assertEqual(store.clean_host(ok)["phone"], "") # 쇼핑몰·두 이름만 필수
for bad in ({}, {**ok, "full_name": ""}, {**ok, "display_name": ""}, {**ok, "platform": ""}, {**ok, "platform": "lazada"}, {**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)
@@ -256,9 +256,9 @@ assert "live_host" in MODULE_KEYS and "live_host" in main.MODULE_LABELS
class Fake:
saved = []
def host_choices(self):
return [{"id": 1, "display_name": "Siti", "full_name": "Siti Binti Awa", "is_active": True}]
return [{"id": 1, "platform": "tiktok", "display_name": "Siti", "full_name": "Siti Binti Awa", "is_active": True}]
def list_hosts(self):
return [{"id": 1, "display_name": "Siti", "full_name": "Siti Binti Awa", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank",
return [{"id": 1, "platform": "tiktok", "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 []
@@ -273,7 +273,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 = {"display_name": "Newbie", "full_name": "New Host", "bank_account": "111"}
new = {"platform": "tiktok", "display_name": "Newbie", "full_name": "New Host", "bank_account": "111"}
def body(c):
who["u"] = adder
@@ -281,12 +281,13 @@ def body(c):
assert 'href="/live/settings"' in sched and 'name="tiktok_handle"' in sched and '<option value="alt.acc">' in sched
page = c.get("/live/settings")
assert page.status_code == 200 and "Siti" in page.text and 'name="full_name"' in page.text
for hidden in ("998877", "Maybank", "s@e.my", 'name="tiktok_handle"', "data-edit='", "/delete", 'name="is_active"'):
for hidden in ("998877", "Maybank", "s@e.my", 'name="tiktok_handle"', "data-edit='", "/delete", 'name="is_active"', "data-active="):
assert hidden not in page.text, hidden
assert c.post("/live/settings/hosts", data=new).json()["ok"]
assert fake.saved == [(None, "New Host", True, "adder@t.local")], fake.saved
assert c.post("/live/settings/hosts", data={**new, "id": "1"}).status_code == 403
assert c.post("/live/settings/hosts/1/delete").status_code == 403
assert c.post("/live/settings/hosts/1/active", data={"is_active": "0"}).status_code == 403 # 토글 = 고치기 권한
assert len(fake.saved) == 1, fake.saved
for no_add in (U("staff@t.local"), chip_only):
@@ -313,13 +314,13 @@ run(body)
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",
OLD = {"id": 1, "platform": "shopee", "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")}]
return [{k: OLD[k] for k in ("id", "platform", "display_name", "full_name", "is_active")}]
def list_hosts(self):
return [OLD]
def get_host(self, host_id):
@@ -333,11 +334,15 @@ class Fake:
return 1
def delete_host(self, host_id):
self.saved.append(("deleted", host_id))
def set_host_active(self, host_id, is_active, *, by):
if host_id != 1:
raise ValueError("호스트를 찾을 수 없습니다.")
self.saved.append(("active", host_id, is_active))
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"}
form = {"id": "1", "platform": "shopee", "display_name": "Nabella", "full_name": "Siti Binti Awa", "is_active": "1"}
def body(c):
who["u"] = editor
@@ -346,6 +351,14 @@ def body(c):
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 \'data-active="/live/settings/hosts/1/active"\' in page and \'src="/static/dispatch/courier/shopee.png"\' in page
assert \'"platform": "shopee"\' in page and page.count(\'name="platform"\') == 2
# 목록 토글 — 사용 여부만
assert c.post("/live/settings/hosts/1/active", data={"is_active": "0"}).json()["ok"] and fake.saved[-1] == ("active", 1, False)
assert c.post("/live/settings/hosts/1/active", data={"is_active": "1"}).json()["ok"] and fake.saved[-1] == ("active", 1, True)
assert c.post("/live/settings/hosts/9/active", data={"is_active": "1"}).status_code == 400
assert c.post("/live/settings/hosts", data={**form, "platform": ""}).status_code == 400 # 쇼핑몰 필수
assert c.post("/live/settings/hosts", data=form).json()["ok"]
host_id, values, active = fake.saved[-1]
@@ -364,6 +377,7 @@ def body(c):
who["u"] = no_edit
assert c.get("/live/settings").status_code == 403
assert c.post("/live/settings/hosts", data=form).status_code == 403
assert c.post("/live/settings/hosts/1/active", data={"is_active": "0"}).status_code == 403
assert len(fake.saved) == count
# 관리자는 빈칸 = 지우기 그대로
@@ -447,7 +461,7 @@ def jpeg():
return raw.getvalue()
def body(c):
host = {"display_name": "S" + tag, "full_name": NAME, "phone": "+60 12-345", "email": "siti@example.my", "address": "Kuala Lumpur",
host = {"platform": "tiktok", "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
@@ -461,6 +475,9 @@ def body(c):
r = c.post("/live/settings/hosts", data=host)
assert r.json()["ok"], r.text
hid = next(h["id"] for h in st.list_hosts() if h["full_name"] == NAME)
assert st.get_host(hid)["platform"] == "tiktok"
assert c.post("/live/settings/hosts/%d/active" % hid, data={"is_active": "0"}).json()["ok"] and st.get_host(hid)["is_active"] is False
assert c.post("/live/settings/hosts/%d/active" % hid, data={"is_active": "1"}).json()["ok"] and st.get_host(hid)["is_active"] is True
page = c.get("/live/settings").text
for field in ("이름 (IC 기준)", "전화번호", "이메일", "주소", "은행명", "계좌번호"):
assert field in page, field
@@ -526,7 +543,7 @@ def body(c):
page = no_korean("/live/?month=2031-03")
assert 'lang="en"' in page and "March 2031" in page and "2031.03.05 (Wed)" in page and "Commission 10% (RM)" in page
cal = no_korean("/live/calendar?month=2031-03")
assert "Jump to Date" in cal and "SATURDAY" in cal and "1 MAR" in cal and "2 Hours (RM50 Base)" in cal and ">Sales<" in cal and "Com (10%)" in cal and "Fee: <b>RM54.80" in cal
assert "SATURDAY" in cal and "1 MAR" in cal and "2 Hours (RM50 Base)" in cal and ">Sales<" in cal and "Com (10%)" in cal and "Fee: <b>RM54.80" in cal
assert "Total Sales:" in cal and "Ad Spend:" in cal and "Host Fee:" in cal and "Total &amp; ROAS" in cal
assert c.post("/live/broadcasts", data={**show, "id": bid, "sales_amount": "abc"}).json()["message"] == "Sales must be a number."
assert c.post("/live/broadcasts", data={**show, "id": bid, "end_time": ""}).json()["message"] == "Enter the End Time."
@@ -537,7 +554,7 @@ def body(c):
assert c.post("/live/ad-spend", data={"day": "2031-03-09", "amount": ""}).json()["ok"]
who["u"] = admin
page = no_korean("/live/settings")
for field in ("Full Name (as per IC)", "Phone Number", "Email", "Address", "Bank Name", "Bank Account Number", "Tiktok Handle"):
for field in ("Full Name (as per IC)", "Phone Number", "Email", "Address", "Bank Name", "Bank Account Number", "Platform"):
assert field in page, field
who["u"] = staff
c.cookies.set("live_lang", "<bad>") # 모르는 값 = 한글