Skip to content

Commit 50cabdb

Browse files
committed
unit - scrapy pipelines actor dataset push
1 parent dfbebd5 commit 50cabdb

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

tests/unit/scrapy/middlewares/test_apify_proxy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def proxy_configuration() -> ProxyConfiguration:
7070
'use_apify_proxy_false',
7171
],
7272
)
73-
def test_middleware_initialization_from_crawler(
73+
def test_initialization_from_crawler(
7474
crawler: Crawler,
7575
monkeypatch: pytest.MonkeyPatch,
7676
settings: dict,
@@ -92,7 +92,7 @@ def test_middleware_initialization_from_crawler(
9292
['http://username:[email protected]:8080', 'http://hsdfgds:[email protected]:5748'],
9393
ids=['example_proxy', 'apify_proxy'],
9494
)
95-
async def test_middleware_retrieves_new_proxy_url(
95+
async def test_retrieves_new_proxy_url(
9696
monkeypatch: pytest.MonkeyPatch,
9797
middleware: ApifyHttpProxyMiddleware,
9898
proxy_configuration: ProxyConfiguration,
@@ -116,7 +116,7 @@ async def mock_new_url() -> str:
116116
],
117117
ids=['valid_example_proxy', 'valid_apify_proxy', 'invalid_proxy_missing_credentials'],
118118
)
119-
async def test_middleware_process_request_with_proxy(
119+
async def test_process_request_with_proxy(
120120
monkeypatch: pytest.MonkeyPatch,
121121
middleware: ApifyHttpProxyMiddleware,
122122
spider: DummySpider,
@@ -144,7 +144,7 @@ async def mock_get_new_proxy_url() -> ParseResult:
144144
[TunnelError(), ValueError()],
145145
ids=['tunnel_error', 'value_error'],
146146
)
147-
def test_middleware_handles_exceptions(
147+
def test_handles_exceptions(
148148
middleware: ApifyHttpProxyMiddleware,
149149
spider: DummySpider,
150150
dummy_request: Request,

tests/unit/scrapy/pipelines/test_actor_dataset_push.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,28 @@ class TestCase:
4343
expected_exception: type[Exception] | None
4444

4545

46-
test_cases = [
47-
TestCase(
48-
item=DummyItem(a='string', b=123, c=False),
49-
item_dict={'a': 'string', 'b': 123, 'c': False},
50-
expected_exception=None,
51-
),
52-
TestCase(
53-
item=TitleItem(url='https://example.com', title='Example'),
54-
item_dict={'url': 'https://example.com', 'title': 'Example'},
55-
expected_exception=None,
56-
),
57-
TestCase(
58-
item=None,
59-
item_dict={},
60-
expected_exception=TypeError,
61-
),
62-
]
63-
64-
65-
@pytest.mark.parametrize('tc', test_cases)
66-
async def test__process_item(
46+
@pytest.mark.parametrize(
47+
'tc',
48+
[
49+
TestCase(
50+
item=DummyItem(a='string', b=123, c=False),
51+
item_dict={'a': 'string', 'b': 123, 'c': False},
52+
expected_exception=None,
53+
),
54+
TestCase(
55+
item=TitleItem(url='https://example.com', title='Example'),
56+
item_dict={'url': 'https://example.com', 'title': 'Example'},
57+
expected_exception=None,
58+
),
59+
TestCase(
60+
item=None,
61+
item_dict={},
62+
expected_exception=TypeError,
63+
),
64+
],
65+
ids=['dummy_item_with_valid_data', 'title_item_with_valid_data', 'none_item_raises_type_error'],
66+
)
67+
async def test_process_item(
6768
monkeypatch: pytest.MonkeyPatch,
6869
pipeline: ActorDatasetPushPipeline,
6970
spider: Spider,

0 commit comments

Comments
 (0)