Skip to content

Commit 3035042

Browse files
committed
Update api_tests.py
1 parent a6325b6 commit 3035042

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

tests/api_tests.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ def anyio_backend():
1616
return "asyncio"
1717

1818

19+
20+
async def test_proxy_ip():
21+
from pyaterochka_api.manager import _pick_https_proxy
22+
proxy = _pick_https_proxy()
23+
24+
if not proxy:
25+
pytest.skip("Proxy not configured")
26+
27+
prx = Proxy(api.proxy)
28+
29+
async with aiohttp.ClientSession() as session:
30+
async with session.get("http://httpbin.org/ip", proxy=prx.as_str()) as resp:
31+
ip = resp.json()["origin"]
32+
33+
assert ip == prx._server.split(":")[0]
34+
35+
36+
1937
@pytest.fixture(scope="session")
2038
async def api():
2139
"""Фикстура для инициализации API в рамках сессии"""
@@ -160,15 +178,3 @@ async def test_download_image(api: PyaterochkaAPI, first_category: dict):
160178
with Image.open(resp) as img:
161179
fmt = img.format.lower()
162180
assert fmt in ("png", "jpeg", "webp")
163-
164-
async def test_proxy_ip(api: PyaterochkaAPI):
165-
if not api.proxy:
166-
pytest.skip("Proxy not configured")
167-
168-
prx = Proxy(api.proxy)
169-
170-
async with aiohttp.ClientSession() as session:
171-
async with session.get("http://httpbin.org/ip", proxy=prx.as_str()) as resp:
172-
ip = resp.json()["origin"]
173-
174-
assert ip == prx._server.split(":")[0]

0 commit comments

Comments
 (0)