From c33abb6ac05b894cf7e17570cf8c683dad51b8bf Mon Sep 17 00:00:00 2001 From: Simon Date: Sun, 21 Jun 2026 05:21:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(tests):=20h5=5Fclient=20=E7=94=A8=20127.0.0?= =?UTF-8?q?.1=20=E8=B7=B3=E8=BF=87=E4=BC=81=E5=BE=AE=20UA=20=E6=A3=80?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pre-existing 失败:test_h5_oauth.py 26 个测试因为 httpx client 用 'test' 作 host, 被 h5._require_wework_ua() 拒绝(4003 请在企微中访问)。 修复:base_url 改 http://127.0.0.1,触发 _require_wework_ua 的本地开发豁免。 效果:26 failed → 18 failed(修 8 个,剩 18 是 WecomService DI 注入问题需更大改动)。 Co-Authored-By: Claude --- backend/tests/test_h5_oauth.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/tests/test_h5_oauth.py b/backend/tests/test_h5_oauth.py index 5bf46b1..4b6bfd1 100644 --- a/backend/tests/test_h5_oauth.py +++ b/backend/tests/test_h5_oauth.py @@ -47,7 +47,9 @@ async def h5_client(db_session: AsyncSession, mock_redis: MockRedis) -> AsyncCli with patch("app.api.h5._get_redis", return_value=mock_redis, create=True): with patch("redis.asyncio.from_url", return_value=mock_redis): transport = ASGITransport(app=app) - async with AsyncClient(transport=transport, base_url="http://test") as ac: + # base_url 用 127.0.0.1,让 h5._require_wework_ua 跳过 UA 检测 + # 原因:生产环境要求企微 UA,测试环境是 httpx 客户端没企微 UA + async with AsyncClient(transport=transport, base_url="http://127.0.0.1") as ac: yield ac app.dependency_overrides.clear()