Skip to content

Commit

Permalink
fix tests regarding expectations for param in rule
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnzZ committed Oct 13, 2022
1 parent 6c8b6a5 commit fc9a9d9
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions tests/test_web_poet_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,13 @@ class SubclassProductPage(ParentProductPage):
assert item == ParentProduct(name="subclass product's name")


# FIXME: tests failing since the PO's to_item() method hasn't been affected by
# the 'to_return' parameter change.
# TODO: Consider "skip_nonitem_fields" for the cases below
@inlineCallbacks
def test_item_return_replaced_by_to_return() -> None:
"""The ``to_return`` parameter passed in ``@handle_urls()`` should be used
instead of the underlying ``Returns[ItemType]`` inside the Page Object.
def test_item_to_return() -> None:
"""The ``to_return`` parameter passed in ``@handle_urls()`` could be requested
to match the rule.
For example, in the code below, the returned item should be ``ReplacedProduct(...)``.
For example, when requesting for ``RelacedProduct``, a ``Product`` item should
be returned by ``ReplacedProductPage``.
..code-block::
Expand All @@ -138,17 +136,21 @@ class ReplacedProductPage(ItemPage[Product]):
...
"""
item = yield crawl_item(ReplacedProduct)
assert item == ReplacedProduct(name="replaced product's name")
assert item == Product(name="replaced product's name")

# Requesting the underlying item type from the PO should still work.
item = yield crawl_item(Product)
assert item == Product(name="product's name")


# FIXME: same case as above
@inlineCallbacks
def test_item_return_replaced_by_to_return_in_subclass() -> None:
"""Same case as with the ``test_item_return_replaced_by_to_return()`` case
above but the ``to_return`` replacement is done in the subclass.
def test_item_to_return_in_subclass() -> None:
"""Same case as with the ``test_item_to_return()`` case above but the
``to_return`` is declared in the subclass.
In the example below, requesting a ``SubclassReplacedProduct`` item should
come from the ``SubclassReplacedProductPage`` page object.
return a ``ParentReplacedProduct`` which comes from the
``SubclassReplacedProductPage`` page object.
..code-block::
Expand All @@ -161,18 +163,21 @@ class SubclassReplacedProductPage(ParentReplacedProductPage):
...
"""
item = yield crawl_item(SubclassReplacedProduct)
assert item == SubclassReplacedProduct(name="subclass replaced product's name")
assert item == ParentReplacedProduct(name="subclass replaced product's name")

# Requesting the underlying item type from the parent PO should still work.
item = yield crawl_item(ParentReplacedProduct)
assert item == ParentReplacedProduct(name="parent replaced product's name")


# FIXME: tests failing since it returns a ``dict``; same case as above
@inlineCallbacks
def test_item_return_standalone() -> None:
"""Despite the PageObject not having ``Returns[ItemType]``, a return type
should still be able to work using the ``to_return`` parameter passed in the
def test_item_to_return_standalone() -> None:
"""Despite the PageObject not having ``Returns[ItemType]``, requesting an
item type should still work using the ``to_return`` parameter from the
``@handle_urls()`` decorator.
For example, the following code below should return a ``StandaloneProduct``
item.
For example, requesting a ``StandaloneProduct`` should return a ``dict`` item
which is the default return type for ``web_poet.ItemPage`` subclasses.
..code-block::
Expand All @@ -181,7 +186,7 @@ class StandaloneProductPage(ItemPage):
...
"""
item = yield crawl_item(StandaloneProduct)
assert item == StandaloneProduct(name="standalone product's name")
assert item == {"name": "standalone product's name"}


@inlineCallbacks
Expand Down

0 comments on commit fc9a9d9

Please sign in to comment.