55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
from datetime import datetime
|
|
|
|
import pytest
|
|
|
|
from proxy_pool.plugins.builtin.checkers.http_anonymity import HttpAnonymityChecker
|
|
from proxy_pool.plugins.protocols import CheckContext
|
|
|
|
|
|
@pytest.fixture
|
|
def checker():
|
|
return HttpAnonymityChecker(
|
|
judge_url="http://httpbin.org/ip",
|
|
timeout=10.0,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def context():
|
|
return CheckContext(
|
|
started_at=datetime.now(),
|
|
http_client=None,
|
|
tcp_latency_ms=50.0,
|
|
)
|
|
|
|
|
|
class TestHttpAnonymityChecker:
|
|
def test_stage_and_priority(self, checker):
|
|
assert checker.stage == 2
|
|
assert checker.priority == 0
|
|
|
|
def test_does_not_skip_any_protocol(self, checker):
|
|
assert checker.should_skip("http") is False
|
|
assert checker.should_skip("https") is False
|
|
assert checker.should_skip("socks4") is False
|
|
assert checker.should_skip("socks5") is False
|
|
|
|
async def test_fails_on_unreachable_proxy(self, checker, context):
|
|
result = await checker.check(
|
|
proxy_ip="192.0.2.1",
|
|
proxy_port=1,
|
|
proxy_protocol="http",
|
|
context=context,
|
|
)
|
|
|
|
assert result.passed is False
|
|
|
|
async def test_fails_on_invalid_socks_proxy(self, checker, context):
|
|
result = await checker.check(
|
|
proxy_ip="192.0.2.1",
|
|
proxy_port=1,
|
|
proxy_protocol="socks5",
|
|
context=context,
|
|
)
|
|
|
|
assert result.passed is False |