|
|
@@ -19,7 +19,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
from kuaishou_tool import config, db, tasks, publish
|
|
|
from kuaishou_tool.publish import (
|
|
|
PublishError, upload_sign, upload_fragment, upload_complete,
|
|
|
- report_slice, submit_slice, do_publish, add_goods,
|
|
|
+ report_slice, submit_slice, set_caption, do_publish, add_goods,
|
|
|
)
|
|
|
|
|
|
logging.disable(logging.CRITICAL) # 静音调度日志,保持测试输出干净
|
|
|
@@ -347,6 +347,37 @@ def test_submit_slice_fail():
|
|
|
assert '提交上传视频失败' in str(e)
|
|
|
|
|
|
|
|
|
+# ═══════════════ ④b set_caption(前端kmi.js标定:updateType=2) ═══════════════
|
|
|
+
|
|
|
+def test_set_caption_ok():
|
|
|
+ fc = FakeClient()
|
|
|
+ fc.script = ok_script()
|
|
|
+ set_caption(fc, '496010274615', '和我一起走进光遇的世界吧~')
|
|
|
+ c = fc.calls[0]
|
|
|
+ assert c['url'] == ('https://s.kwaixiaodian.com/gateway/short/video/b/pc/'
|
|
|
+ 'ownVideo/update?caver=2')
|
|
|
+ b = c['json']
|
|
|
+ assert b == {'sliceId': 496010274615, 'title': '和我一起走进光遇的世界吧~',
|
|
|
+ 'updateType': 2} # 前端handleVideoCaptionChange原样键
|
|
|
+
|
|
|
+
|
|
|
+def test_set_caption_empty_skip():
|
|
|
+ fc = FakeClient()
|
|
|
+ fc.script = ok_script()
|
|
|
+ set_caption(fc, '123', '') # 空标题不发请求
|
|
|
+ assert fc.calls == []
|
|
|
+
|
|
|
+
|
|
|
+def test_set_caption_fail():
|
|
|
+ fc = FakeClient()
|
|
|
+ fc.script = {'ownVideo/update': FakeResp({'error_msg': '描述被拒'})}
|
|
|
+ try:
|
|
|
+ set_caption(fc, '123', 't')
|
|
|
+ raise AssertionError('失败应抛 PublishError')
|
|
|
+ except PublishError as e:
|
|
|
+ assert '作品描述提交失败' in str(e)
|
|
|
+
|
|
|
+
|
|
|
# ═══════════════ ⑤ do_publish ═══════════════
|
|
|
|
|
|
def test_do_publish_ok():
|
|
|
@@ -357,7 +388,7 @@ def test_do_publish_ok():
|
|
|
assert 'ownVideo/publish?caver=2' in c['url']
|
|
|
b = c['json']
|
|
|
assert b == {'sliceId': 496010274615, 'needConfirmation': True,
|
|
|
- 'fromUserId': '', 'caption': '爆款标题'} # P1标定+C线W6 caption
|
|
|
+ 'fromUserId': ''} # P1标定:描述不走publish的caption(无效字段)
|
|
|
assert r['ok'] is True and r['photo_id'] == 'PHOTO_777'
|
|
|
assert not fc.by('ownVideo/delete') # 成功不回滚
|
|
|
|
|
|
@@ -472,7 +503,8 @@ def test_publish_full_ok_with_goods():
|
|
|
assert res['photo_id'] == 'PHOTO_777'
|
|
|
assert res['goods'] and res['goods']['ok'] is True
|
|
|
assert len(sleeps) == 5 and sleeps[0] == (0, 0) # 相邻步骤间延时5次
|
|
|
- # 调用顺序(P1标定):sign → fragment → complete → report → update → publish → item/save
|
|
|
+ # 调用顺序(P1标定+描述update):sign→fragment→complete→report→update(封面)→
|
|
|
+ # update(描述updateType=2)→publish→item/save
|
|
|
order = []
|
|
|
marks = ('sign/generate', 'upload/fragment', 'upload/complete', 'ownVideo/report',
|
|
|
'ownVideo/update', 'ownVideo/publish', 'ownVideo/delete', 'item/save')
|
|
|
@@ -482,8 +514,12 @@ def test_publish_full_ok_with_goods():
|
|
|
order.append(m)
|
|
|
break
|
|
|
assert order == ['sign/generate', 'upload/fragment', 'upload/complete',
|
|
|
- 'ownVideo/report', 'ownVideo/update', 'ownVideo/publish',
|
|
|
- 'item/save'], order
|
|
|
+ 'ownVideo/report', 'ownVideo/update', 'ownVideo/update',
|
|
|
+ 'ownVideo/publish', 'item/save'], order
|
|
|
+ ups = fc.by('ownVideo/update')
|
|
|
+ assert ups[0]['json']['updateType'] == 3 # 先封面
|
|
|
+ assert ups[1]['json']['updateType'] == 2 # 后描述
|
|
|
+ assert ups[1]['json']['title'] == '测试标题ABC' # 描述=biaoti标题
|
|
|
|
|
|
|
|
|
def test_publish_full_no_goods_and_title_fallback():
|