| 123456789101112131415161718192021222324252627282930 |
- """web wx-qr create/status API。"""
- from unittest.mock import patch
- from fastapi.testclient import TestClient
- from app.main import app
- from app.services import wx_qr_session
- client = TestClient(app)
- def setup_function():
- wx_qr_session._memory_clear_for_tests()
- def test_wx_qr_create_and_poll_pending():
- with patch("app.services.wx_qr_session._redis", return_value=None), patch(
- "app.api.public.get_unlimited_wxacode",
- return_value=b"\x89PNG\r\n\x1a\n",
- ):
- r = client.post("/api/web/auth/wx-qr/create")
- assert r.status_code == 200
- body = r.json()
- assert body.get("code") == 200
- data = body["data"]
- sid = data["sessionId"]
- assert data["qrImageBase64"].startswith("data:image/")
- st = client.get("/api/web/auth/wx-qr/status", params={"sessionId": sid})
- assert st.status_code == 200
- assert st.json()["data"]["status"] == "pending"
|