From 06078db34a27a19fb821d1a9b0654679e11db853 Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 15 Mar 2026 16:38:20 -0400 Subject: [PATCH] test: add tests for HTTP anonymity checker --- tests/plugins/test_http_anonymity_checker.py | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/plugins/test_http_anonymity_checker.py diff --git a/tests/plugins/test_http_anonymity_checker.py b/tests/plugins/test_http_anonymity_checker.py new file mode 100644 index 0000000..5e12732 --- /dev/null +++ b/tests/plugins/test_http_anonymity_checker.py @@ -0,0 +1,55 @@ +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 \ No newline at end of file