diff --git a/tests/plugins/test_plaintext_parser.py b/tests/plugins/test_plaintext_parser.py new file mode 100644 index 0000000..2f78eff --- /dev/null +++ b/tests/plugins/test_plaintext_parser.py @@ -0,0 +1,61 @@ +import uuid + +import pytest + +from proxy_pool.plugins.builtin.parsers.plaintext import PlaintextParser + + +@pytest.fixture +def parser(): + return PlaintextParser() + + +class TestSupports: + def test_matches_txt_extension(self, parser): + assert parser.supports("https://example.com/proxies.txt") is True + + def test_matches_plain_in_url(self, parser): + assert parser.supports("https://example.com/plain-list") is True + + def test_rejects_unrelated_url(self, parser): + assert parser.supports("https://example.com/proxies.json") is False + + +class TestParse: + async def test_parses_valid_lines(self, parser): + raw = b"192.168.1.1:8080\n10.0.0.1:3128\n" + source_id = uuid.uuid4() + + results = await parser.parse(raw, "http://example.com", source_id, "http") + + assert len(results) == 2 + assert results[0].ip == "192.168.1.1" + assert results[0].port == 8080 + assert results[0].protocol == "http" + assert results[0].source_id == source_id + + async def test_skips_invalid_lines(self, parser): + raw = b"192.168.1.1:8080\nnot a proxy\n\n# comment\n10.0.0.1:3128\n" + + results = await parser.parse(raw, "http://example.com", None, "http") + + assert len(results) == 2 + + async def test_handles_empty_input(self, parser): + results = await parser.parse(b"", "http://example.com", None, "http") + + assert results == [] + + async def test_handles_bad_encoding(self, parser): + raw = b"192.168.1.1:8080\n\xff\xfe broken\n10.0.0.1:3128\n" + + results = await parser.parse(raw, "http://example.com", None, "http") + + assert len(results) == 2 + + async def test_uses_default_protocol(self, parser): + raw = b"1.2.3.4:1080\n" + + results = await parser.parse(raw, "http://example.com", None, "socks5") + + assert results[0].protocol == "socks5" \ No newline at end of file diff --git a/tests/plugins/test_tcp_checker.py b/tests/plugins/test_tcp_checker.py new file mode 100644 index 0000000..6f3b8dc --- /dev/null +++ b/tests/plugins/test_tcp_checker.py @@ -0,0 +1,32 @@ +import asyncio +from datetime import datetime + +import pytest + +from proxy_pool.plugins.builtin.checkers.tcp_connect import TcpConnectChecker +from proxy_pool.plugins.protocols import CheckContext + + +@pytest.fixture +def checker(): + return TcpConnectChecker(timeout=2.0) + + +@pytest.fixture +def context(): + return CheckContext( + started_at=datetime.now(), + http_client=None, + ) + + +class TestTcpConnect: + async def test_fails_on_unreachable_host(self, checker, context): + result = await checker.check("192.0.2.1", 1, "http", context) + + assert result.passed is False + assert "timed out" in result.detail or "failed" in result.detail + + async def test_never_skips(self, checker): + assert checker.should_skip("http") is False + assert checker.should_skip("socks5") is False \ No newline at end of file