Skip to content

Commit 395b542

Browse files
committed
replace proxy logic
1 parent 30458ae commit 395b542

2 files changed

Lines changed: 1 addition & 25 deletions

File tree

chizhik_api/manager.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
from .endpoints.geolocation import ClassGeolocation
2222

2323

24-
def _pick_https_proxy() -> str | None:
25-
"""Возвращает прокси из HTTPS_PROXY/https_proxy (если заданы)."""
26-
return os.getenv("HTTPS_PROXY") or os.getenv("https_proxy")
27-
28-
2924
@dataclass
3025
class ChizhikAPI(ApiParent):
3126
"""
@@ -36,7 +31,7 @@ class ChizhikAPI(ApiParent):
3631
"""Время ожидания ответа от сервера в миллисекундах."""
3732
headless: bool = True
3833
"""Запускать браузер в headless режиме?"""
39-
proxy: str | dict | None = field(default_factory=_pick_https_proxy)
34+
proxy: str | dict | None = field(default_factory=Proxy.from_env)
4035
"""Прокси-сервер для всех запросов (если нужен). По умолчанию берет из окружения (если есть).
4136
Принимает как формат Playwright, так и строчный формат."""
4237
browser_opts: dict[str, Any] = field(default_factory=dict)

tests/api_test.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,6 @@ def anyio_backend():
2121
return "asyncio"
2222

2323

24-
async def test_proxy_ip():
25-
from chizhik_api.manager import _pick_https_proxy
26-
27-
proxy = _pick_https_proxy()
28-
29-
if not proxy:
30-
pytest.skip("Proxy not configured")
31-
32-
prx = Proxy(proxy)
33-
34-
async with aiohttp.ClientSession() as session:
35-
async with session.get("http://httpbin.org/ip", proxy=prx.as_str()) as resp:
36-
ip = (await resp.json())["origin"]
37-
38-
assert (
39-
ip == prx._server.removeprefix("http://").removeprefix("https://").split(":")[0]
40-
)
41-
42-
4324
@pytest.fixture(scope="session")
4425
async def api():
4526
"""Фикстура для инициализации API в рамках сессии."""

0 commit comments

Comments
 (0)