34 lines
995 B
Python
34 lines
995 B
Python
"""web wx-qr create/status API。"""
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import app
|
|
from app.services import wx_qr_session
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def force_memory_backend(monkeypatch):
|
|
monkeypatch.setattr(wx_qr_session, "_redis", lambda: None)
|
|
wx_qr_session._memory_clear_for_tests()
|
|
|
|
|
|
def test_wx_qr_create_and_poll_pending():
|
|
with 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"
|