from app import wechat from app.config import Settings class FakeResponse: def __init__(self, payload: dict): self.payload = payload def json(self): return self.payload def test_get_access_token_uses_configured_process_proxy(monkeypatch): call = {} def fake_get(_url, *, params, timeout, **kwargs): call.update(params=params, timeout=timeout, **kwargs) return FakeResponse({"access_token": "test-access-token", "expires_in": 7200}) monkeypatch.setattr(wechat.httpx, "get", fake_get) token = wechat.get_access_token( Settings(_env_file=None, wechat_miniapp_appid="wx-proxy-test", wechat_miniapp_secret="test-secret") ) assert token == "test-access-token" assert call["trust_env"] is True def test_exchange_phone_code_uses_configured_process_proxy(monkeypatch): call = {} def fake_post(_url, *, params, json, timeout, **kwargs): call.update(params=params, json=json, timeout=timeout, **kwargs) return FakeResponse( { "errcode": 0, "phone_info": {"phoneNumber": "10000000000"}, } ) monkeypatch.setattr(wechat, "get_access_token", lambda _settings=None: "test-access-token") monkeypatch.setattr(wechat.httpx, "post", fake_post) phone = wechat.exchange_phone_code("phone-code") assert phone == "10000000000" assert call["trust_env"] is True