|
24 | 24 | from scrapy_poet.page_input_providers import ( |
25 | 25 | PageObjectInputProvider |
26 | 26 | ) |
| 27 | +from web_poet import default_registry |
27 | 28 | from web_poet.page_inputs import ResponseData |
28 | 29 | from scrapy_poet import DummyResponse |
29 | 30 | from tests.utils import (HtmlResource, |
@@ -350,3 +351,26 @@ def get_middleware(settings): |
350 | 351 | mock.call('/tmp/cache', compressed=True), |
351 | 352 | mock.call().close() |
352 | 353 | ] |
| 354 | + |
| 355 | + |
| 356 | +@inlineCallbacks |
| 357 | +def test_web_poet_integration(settings): |
| 358 | + """This tests scrapy-poet's integration with web-poet most especially when |
| 359 | + populating override settings via: |
| 360 | +
|
| 361 | + from web_poet import default_registry |
| 362 | +
|
| 363 | + SCRAPY_POET_OVERRIDES = default_registry.get_overrides() |
| 364 | + """ |
| 365 | + |
| 366 | + # Only import them in this test scope since they need to be synced with |
| 367 | + # the URL of the Page Object annotated with @handle_urls. |
| 368 | + from tests.po_lib import DOMAIN, PORT, POOverriden |
| 369 | + |
| 370 | + # Override rules are defined in `tests/po_lib/__init__.py`. |
| 371 | + settings["SCRAPY_POET_OVERRIDES"] = default_registry.get_overrides() |
| 372 | + |
| 373 | + item, url, _ = yield crawl_single_item( |
| 374 | + spider_for(POOverriden), ProductHtml, settings, port=PORT |
| 375 | + ) |
| 376 | + assert item == {"msg": "PO replacement"} |
0 commit comments