From 24faaf9d473da039e4521dcd49aa0b17580641b7 Mon Sep 17 00:00:00 2001 From: marco Date: Thu, 28 May 2026 10:29:20 +0800 Subject: [PATCH] =?UTF-8?q?test(coupon-proxy):=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E5=B7=B2=E8=BF=87=E6=97=B6=E7=9A=84=20401=20=E9=89=B4=E6=9D=83?= =?UTF-8?q?=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit coupon/step MVP 阶段已去鉴权(见「待办与技术债.md」已解决),但 test_coupon_step_requires_auth 仍断言"无 token → 401",baseline 实际走到上游 拿 502,这条用例长期红灯。改为 mock httpx 验证不带 token 也能正常透传,与新加的 compare 端点 no-auth 测试一致。 Co-Authored-By: Claude Opus 4.7 (1M context) --- tests/test_coupon_proxy.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/test_coupon_proxy.py b/tests/test_coupon_proxy.py index 41033e9..c993181 100644 --- a/tests/test_coupon_proxy.py +++ b/tests/test_coupon_proxy.py @@ -44,10 +44,21 @@ def access_token(client) -> str: return r.json()["access_token"] -def test_coupon_step_requires_auth(client) -> None: - """无 token → 401(get_current_user 拦下)。""" - r = client.post("/api/v1/coupon/step", json=_stub_request_body()) - assert r.status_code == 401 +def test_coupon_step_no_auth_required(client) -> None: + """MVP 不鉴权:不带 token 也能转发(已去掉 CurrentUser,device_id 透传)。 + + 历史:本测试原断言"无 token → 401",但 coupon/step 已去鉴权(见 docs/待办与 + 技术债.md「已解决」),401 断言已过时,改为验证不带 token 也能正常透传。 + """ + async def fake_post(self, url, json=None, **kw): + mock_resp = MagicMock() + mock_resp.status_code = 200 + mock_resp.json = lambda: {"success": True} + return mock_resp + + with patch.object(httpx.AsyncClient, "post", fake_post): + r = client.post("/api/v1/coupon/step", json=_stub_request_body()) + assert r.status_code == 200, r.text def test_coupon_step_passes_body_through(client, access_token) -> None: