feat(라이브): 틱톡 계정을 호스트에서 방송으로 옮김
호스트가 메인 계정 외 다른 계정에서도 방송하므로 호스트 설정에서 틱톡 핸들을 빼고 방송 추가·고치기 창에서 방송마다 입력한다. 쓴 적 있는 계정을 입력 제안으로 보여 준다. 마이그레이션 003: live_broadcasts.tiktok_handle 추가, 기존 방송에 호스트의 지금 계정 복사. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+30
-13
@@ -62,14 +62,28 @@ 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",
|
||||
"bank_name": "Maybank", "bank_account": "1234-5678", "tiktok_handle": "@siti.live"})
|
||||
self.assertEqual((got["full_name"], got["tiktok_handle"]), ("Siti Aisyah", "siti.live"))
|
||||
self.assertEqual(got["full_name"], "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": "A", "tiktok_handle": "한글"},
|
||||
{"full_name": "x" * 201}):
|
||||
{"full_name": "A", "bank_account": "12a"}, {"full_name": "x" * 201}):
|
||||
with self.assertRaises(ValueError, msg=bad):
|
||||
store.clean_host(bad)
|
||||
|
||||
def test_broadcast_account(self):
|
||||
good = {"host_id": "3", "broadcast_date": "2026-11-04", "start_time": "20:00", "end_time": "22:00"}
|
||||
self.assertEqual(store.clean_broadcast(good)["tiktok_handle"], "") # 선택 칸
|
||||
self.assertEqual(store.clean_broadcast({**good, "tiktok_handle": "https://www.tiktok.com/@alt.acc?lang=en"})["tiktok_handle"], "alt.acc")
|
||||
for bad in ("한글", "x" * 65):
|
||||
with self.assertRaises(ValueError, msg=bad):
|
||||
store.clean_broadcast({**good, "tiktok_handle": bad})
|
||||
|
||||
def test_edit_keeps_broadcast_account(self):
|
||||
"""고치기 창에 계정이 채워져야 저장하면서 지워지지 않는다."""
|
||||
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"))
|
||||
|
||||
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"):
|
||||
self.assertEqual(store.clean_handle(raw), "siti.live", raw)
|
||||
@@ -86,7 +100,7 @@ class StoreTests(unittest.TestCase):
|
||||
got = store.clean_broadcast({"host_id": "3", "broadcast_date": "2026-11-04", "start_time": "20:00", "end_time": "22:00",
|
||||
"venue": " Studio ", "sales_amount": "100"})
|
||||
self.assertEqual(got, {"host_id": 3, "broadcast_date": date(2026, 11, 4), "start_time": time(20, 0), "end_time": time(22, 0),
|
||||
"venue": "Studio", "sales_amount": Decimal("100.00")})
|
||||
"venue": "Studio", "tiktok_handle": "", "sales_amount": Decimal("100.00")})
|
||||
good = {"host_id": "3", "broadcast_date": "2026-11-04", "start_time": "20:00", "end_time": "22:00"}
|
||||
for over in ({"host_id": ""}, {"host_id": "x"}, {"broadcast_date": ""}, {"broadcast_date": "2026-13-01"}, {"start_time": ""},
|
||||
{"start_time": "25:00"}, {"end_time": ""}, {"end_time": "nope"}, {"end_time": "20:00"}, {"venue": "x" * 201}, {"sales_amount": "-5"}):
|
||||
@@ -226,12 +240,14 @@ 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", "tiktok_handle": "siti", "is_active": True}]
|
||||
return [{"id": 1, "full_name": "Siti", "is_active": True}]
|
||||
def list_hosts(self):
|
||||
return [{"id": 1, "full_name": "Siti", "phone": "012", "email": "s@e.my", "address": "KL", "bank_name": "Maybank",
|
||||
"bank_account": "998877", "tiktok_handle": "siti", "is_active": True}]
|
||||
"bank_account": "998877", "is_active": True}]
|
||||
def list_broadcasts(self, start, end):
|
||||
return []
|
||||
def account_choices(self):
|
||||
return ["MainAccount", "alt.acc"]
|
||||
def save_host(self, host_id, values, *, is_active, by):
|
||||
self.saved.append((host_id, values["full_name"], is_active, by))
|
||||
return 2
|
||||
@@ -245,10 +261,11 @@ new = {"full_name": "New Host", "bank_account": "111"}
|
||||
|
||||
def body(c):
|
||||
who["u"] = adder
|
||||
assert 'href="/live/settings"' in c.get("/live/").text
|
||||
sched = c.get("/live/").text
|
||||
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", "data-edit='", "/delete", 'name="is_active"'):
|
||||
for hidden in ("998877", "Maybank", "s@e.my", 'name="tiktok_handle"', "data-edit='", "/delete", 'name="is_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
|
||||
@@ -316,7 +333,7 @@ def jpeg():
|
||||
|
||||
def body(c):
|
||||
host = {"full_name": NAME, "phone": "+60 12-345", "email": "siti@example.my", "address": "Kuala Lumpur",
|
||||
"bank_name": "Maybank", "bank_account": ACCOUNT, "tiktok_handle": "@siti.%s" % tag, "is_active": "1"}
|
||||
"bank_name": "Maybank", "bank_account": ACCOUNT, "is_active": "1"}
|
||||
# ── 호스트 설정 = ERP 관리자만 ──
|
||||
who["u"] = staff
|
||||
assert c.get("/live/settings").status_code == 403
|
||||
@@ -330,17 +347,17 @@ def body(c):
|
||||
assert r.json()["ok"], r.text
|
||||
hid = next(h["id"] for h in st.list_hosts() if h["full_name"] == NAME)
|
||||
page = c.get("/live/settings").text
|
||||
for field in ("이름 (IC 기준)", "전화번호", "이메일", "주소", "은행명", "계좌번호", "틱톡 핸들"):
|
||||
for field in ("이름 (IC 기준)", "전화번호", "이메일", "주소", "은행명", "계좌번호"):
|
||||
assert field in page, field
|
||||
assert ACCOUNT in page and "Siti <b>" in page and "<b>" + tag not in page
|
||||
assert st.list_hosts() and next(h for h in st.list_hosts() if h["id"] == hid)["tiktok_handle"] == "siti." + tag
|
||||
assert "틱톡 핸들" not in page and 'name="tiktok_handle"' not in page # 계정은 방송마다
|
||||
|
||||
# ── 스케줄: 일반 권한자도 추가·고치기, 화면에 계좌·주소 없음 ──
|
||||
who["u"] = staff
|
||||
page = c.get("/live/?month=2031-03").text
|
||||
assert 'value="%d"' % hid in page and "@siti." + tag in page
|
||||
assert 'value="%d"' % hid in page
|
||||
assert ACCOUNT not in page and "Kuala Lumpur" not in page and "Maybank" not in page
|
||||
show = {"host_id": hid, "broadcast_date": "2031-03-05", "start_time": "20:00", "end_time": "22:30", "venue": "KL Studio", "sales_amount": "1,234.5"}
|
||||
show = {"host_id": hid, "broadcast_date": "2031-03-05", "start_time": "20:00", "end_time": "22:30", "venue": "KL Studio", "tiktok_handle": "@siti.%s" % tag, "sales_amount": "1,234.5"}
|
||||
assert c.post("/live/broadcasts", data={**show, "host_id": ""}).status_code == 400
|
||||
assert c.post("/live/broadcasts", data={**show, "host_id": 99999999}).status_code == 400
|
||||
junk = c.post("/live/broadcasts", data=show, files=[("images", ("x.jpg", b"not an image", "image/jpeg"))])
|
||||
|
||||
Reference in New Issue
Block a user