Skip to content

Commit dfbebd5

Browse files
committed
unit - scrapy middleware apify proxy
1 parent e684b92 commit dfbebd5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/unit/scrapy/middlewares/test_apify_proxy.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ def proxy_configuration() -> ProxyConfiguration:
6060
({'APIFY_PROXY_SETTINGS': {'useApifyProxy': None}}, NotConfigured),
6161
({'APIFY_PROXY_SETTINGS': {'useApifyProxy': False}}, NotConfigured),
6262
],
63+
ids=[
64+
'valid_proxy_settings_enabled',
65+
'valid_proxy_settings_with_groups',
66+
'no_settings',
67+
'irrelevant_setting',
68+
'empty_proxy_settings',
69+
'use_apify_proxy_none',
70+
'use_apify_proxy_false',
71+
],
6372
)
64-
def test__from_crawler(
73+
def test_middleware_initialization_from_crawler(
6574
crawler: Crawler,
6675
monkeypatch: pytest.MonkeyPatch,
6776
settings: dict,
@@ -81,8 +90,9 @@ def test__from_crawler(
8190
@pytest.mark.parametrize(
8291
'expected_proxy_url',
8392
['http://username:[email protected]:8080', 'http://hsdfgds:[email protected]:5748'],
93+
ids=['example_proxy', 'apify_proxy'],
8494
)
85-
async def test__get_new_proxy_url(
95+
async def test_middleware_retrieves_new_proxy_url(
8696
monkeypatch: pytest.MonkeyPatch,
8797
middleware: ApifyHttpProxyMiddleware,
8898
proxy_configuration: ProxyConfiguration,
@@ -104,8 +114,9 @@ async def mock_new_url() -> str:
104114
('http://user123:[email protected]:5748', None, b'Basic dXNlcjEyMzpwYXNzNDU2'),
105115
('http://@proxy.example.com:2943', ValueError, b''),
106116
],
117+
ids=['valid_example_proxy', 'valid_apify_proxy', 'invalid_proxy_missing_credentials'],
107118
)
108-
async def test__process_request(
119+
async def test_middleware_process_request_with_proxy(
109120
monkeypatch: pytest.MonkeyPatch,
110121
middleware: ApifyHttpProxyMiddleware,
111122
spider: DummySpider,
@@ -131,8 +142,9 @@ async def mock_get_new_proxy_url() -> ParseResult:
131142
@pytest.mark.parametrize(
132143
'exception',
133144
[TunnelError(), ValueError()],
145+
ids=['tunnel_error', 'value_error'],
134146
)
135-
def test__process_exception(
147+
def test_middleware_handles_exceptions(
136148
middleware: ApifyHttpProxyMiddleware,
137149
spider: DummySpider,
138150
dummy_request: Request,

0 commit comments

Comments
 (0)