test(coupon-proxy): 修正已过时的 401 鉴权断言

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) <noreply@anthropic.com>
This commit is contained in:
2026-05-28 10:29:20 +08:00
parent 007f8a0eb2
commit 24faaf9d47
+14 -3
View File
@@ -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 拦下)。"""
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 == 401
assert r.status_code == 200, r.text
def test_coupon_step_passes_body_through(client, access_token) -> None: