返回 Social Auto Upload
test_tencent_verification_dialog.py
根目录 / tests / test_tencent_verification_dialog.py
1 import asyncio
2 from pathlib import Path
3
4 from patchright.async_api import async_playwright
5
6 from uploader.tencent_uploader.main import TencentBaseUploader
7
8
9 def test_wait_for_realtime_verification_saves_qr_and_resumes(tmp_path: Path):
10 async def scenario():
11 async with async_playwright() as playwright:
12 browser = await playwright.chromium.launch(headless=True, channel="chrome")
13 page = await browser.new_page()
14 await page.set_content(
15 """
16 <div class="weui-desktop-dialog__wrp">
17 <div>为保障账号安全,需用管理员微信扫码完成实名验证后才能继续发表</div>
18 <div class="qr">QR</div>
19 </div>
20 """
21 )
22 uploader = TencentBaseUploader(publish_date=0, account_file="unused")
23 qr_path = tmp_path / "verification.png"
24
25 async def dismiss_dialog():
26 await page.wait_for_timeout(150)
27 await page.locator("div.weui-desktop-dialog__wrp").evaluate("el => el.remove()")
28
29 dismiss_task = asyncio.create_task(dismiss_dialog())
30 result = await uploader.wait_for_realtime_verification(
31 page,
32 qr_path=qr_path,
33 timeout_seconds=2,
34 poll_interval_seconds=0.05,
35 )
36 await dismiss_task
37 await browser.close()
38
39 assert result == qr_path
40 assert qr_path.is_file()
41 assert qr_path.stat().st_size > 0
42
43 asyncio.run(scenario())
44
44 lines PYTHON