fix(tests): h5_client 用 127.0.0.1 跳过企微 UA 检测

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 <noreply@anthropic.com>
This commit is contained in:
Simon
2026-06-21 05:21:50 +08:00
parent a9b97deacd
commit c33abb6ac0
+3 -1
View File
@@ -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("app.api.h5._get_redis", return_value=mock_redis, create=True):
with patch("redis.asyncio.from_url", return_value=mock_redis): with patch("redis.asyncio.from_url", return_value=mock_redis):
transport = ASGITransport(app=app) 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 yield ac
app.dependency_overrides.clear() app.dependency_overrides.clear()