import asyncio import httpx from app.nqi.client import NqiClient def test_keepalive_walks_the_post_login_pages(): seen: list[tuple[str, str]] = [] def handler(request: httpx.Request) -> httpx.Response: seen.append((request.method, request.url.path)) if request.url.path.endswith("/getCasUser"): return httpx.Response(200, json={"loginId": "a", "userName": "测试", "cityName": "江门", "orgName": ""}) return httpx.Response(200, text="ok") async def run(): client = NqiClient() await client.aclose() client.client = httpx.AsyncClient(transport=httpx.MockTransport(handler)) client.import_cookies([{"name": "CASTGC", "value": "TGT-test", "domain": "nqi.gmcc.net", "path": "/"}]) try: user = await client.replay_login_landing() finally: await client.aclose() return user user = asyncio.run(run()) paths = [path for _method, path in seen] assert user["loginId"] == "a" assert "/pro-portal/" in paths assert "/pro-portal/pure/Home!getUserInfo.action" in paths assert "/pro-portalv2/api/cas/getCasUser" in paths assert "/pro-portal/pure/urlAction.action" in paths assert "/pro-adhoc/index" in paths assert any(item[0] == "POST" and item[1].endswith("/checkUserPasswordUpdated") for item in seen)