/
pa1ch
/
FitAssistant
Обзор
Документация
Войти
/
pa1ch
/
FitAssistant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
tests/unit/test_proxy.py
58 строк
2 KB
Pavel Chugaev
fix(ai): Gemini через прокси — прокидываем http_client и щедрый таймаут
14 июл 2026, 00:56
14 июл 2026, 00:56
1e90792
Код
Авторство
О чём код?
"""Tests for outbound proxy wiring (Telegram + AI providers via PROXY_URL).""" from unittest.mock import patch import httpx from aiohttp_socks import ProxyConnector, ProxyType from app.bot.utils import build_bot_session from app.services.http import normalize_proxy_url, proxied_async_client def test_normalize_upgrades_socks5_to_remote_dns(): assert normalize_proxy_url("socks5://u:p@host:1080") == "socks5h://u:p@host:1080" def test_normalize_leaves_other_schemes_untouched(): assert normalize_proxy_url("http://host:8080") == "http://host:8080" assert normalize_proxy_url("socks5h://host:1080") == "socks5h://host:1080" def test_proxied_client_none_without_proxy(): with patch("app.services.http.settings.proxy_url", ""): assert proxied_async_client() is None def test_proxied_client_built_with_proxy(): with patch("app.services.http.settings.proxy_url", "socks5://u:p@host:1080"): client = proxied_async_client() assert isinstance(client, httpx.AsyncClient) def test_proxied_client_has_generous_ai_timeout(): """The proxied client must carry a long read timeout — google-genai (Gemini) inherits the timeout straight from this client, so httpx's 5s default would make Gemini time out on any real answer.""" with patch("app.services.http.settings.proxy_url", "socks5://u:p@host:1080"): client = proxied_async_client() assert client is not None assert client.timeout.read == 600.0 def test_bot_session_none_without_proxy(): with patch("app.bot.utils.settings.proxy_url", ""): assert build_bot_session() is None def test_bot_session_uses_socks_connector_with_proxy(): with patch("app.bot.utils.settings.proxy_url", "socks5://user:secret@1.2.3.4:1080"): session = build_bot_session() assert session is not None assert session._connector_type is ProxyConnector init = session._connector_init assert init["proxy_type"] is ProxyType.SOCKS5 assert init["host"] == "1.2.3.4" assert init["port"] == 1080 assert init["username"] == "user" assert init["password"] == "secret" assert init["rdns"] is True