Skip to content

Commit dd536d0

Browse files
committed
fix tests regarding expectations for param in rule
1 parent a58b250 commit dd536d0

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

tests/test_web_poet_rules.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,13 @@ class SubclassProductPage(ParentProductPage):
121121
assert item == ParentProduct(name="subclass product's name")
122122

123123

124-
# FIXME: tests failing since the PO's to_item() method hasn't been affected by
125-
# the 'to_return' parameter change.
126-
# TODO: Consider "skip_nonitem_fields" for the cases below
127124
@inlineCallbacks
128-
def test_item_return_replaced_by_to_return() -> None:
129-
"""The ``to_return`` parameter passed in ``@handle_urls()`` should be used
130-
instead of the underlying ``Returns[ItemType]`` inside the Page Object.
125+
def test_item_to_return() -> None:
126+
"""The ``to_return`` parameter passed in ``@handle_urls()`` could be requested
127+
to match the rule.
131128
132-
For example, in the code below, the returned item should be ``ReplacedProduct(...)``.
129+
For example, when requesting for ``RelacedProduct``, a ``Product`` item should
130+
be returned by ``ReplacedProductPage``.
133131
134132
..code-block::
135133
@@ -138,17 +136,21 @@ class ReplacedProductPage(ItemPage[Product]):
138136
...
139137
"""
140138
item = yield crawl_item(ReplacedProduct)
141-
assert item == ReplacedProduct(name="replaced product's name")
139+
assert item == Product(name="replaced product's name")
140+
141+
# Requesting the underlying item type from the PO should still work.
142+
item = yield crawl_item(Product)
143+
assert item == Product(name="product's name")
142144

143145

144-
# FIXME: same case as above
145146
@inlineCallbacks
146-
def test_item_return_replaced_by_to_return_in_subclass() -> None:
147-
"""Same case as with the ``test_item_return_replaced_by_to_return()`` case
148-
above but the ``to_return`` replacement is done in the subclass.
147+
def test_item_to_return_in_subclass() -> None:
148+
"""Same case as with the ``test_item_to_return()`` case above but the
149+
``to_return`` is declared in the subclass.
149150
150151
In the example below, requesting a ``SubclassReplacedProduct`` item should
151-
come from the ``SubclassReplacedProductPage`` page object.
152+
return a ``ParentReplacedProduct`` which comes from the
153+
``SubclassReplacedProductPage`` page object.
152154
153155
..code-block::
154156
@@ -161,18 +163,21 @@ class SubclassReplacedProductPage(ParentReplacedProductPage):
161163
...
162164
"""
163165
item = yield crawl_item(SubclassReplacedProduct)
164-
assert item == SubclassReplacedProduct(name="subclass replaced product's name")
166+
assert item == ParentReplacedProduct(name="subclass replaced product's name")
167+
168+
# Requesting the underlying item type from the parent PO should still work.
169+
item = yield crawl_item(ParentReplacedProduct)
170+
assert item == ParentReplacedProduct(name="parent replaced product's name")
165171

166172

167-
# FIXME: tests failing since it returns a ``dict``; same case as above
168173
@inlineCallbacks
169-
def test_item_return_standalone() -> None:
170-
"""Despite the PageObject not having ``Returns[ItemType]``, a return type
171-
should still be able to work using the ``to_return`` parameter passed in the
174+
def test_item_to_return_standalone() -> None:
175+
"""Despite the PageObject not having ``Returns[ItemType]``, requesting an
176+
item type should still work using the ``to_return`` parameter from the
172177
``@handle_urls()`` decorator.
173178
174-
For example, the following code below should return a ``StandaloneProduct``
175-
item.
179+
For example, requesting a ``StandaloneProduct`` should return a ``dict`` item
180+
which is the default return type for ``web_poet.ItemPage`` subclasses.
176181
177182
..code-block::
178183
@@ -181,7 +186,7 @@ class StandaloneProductPage(ItemPage):
181186
...
182187
"""
183188
item = yield crawl_item(StandaloneProduct)
184-
assert item == StandaloneProduct(name="standalone product's name")
189+
assert item == {"name": "standalone product's name"}
185190

186191

187192
@inlineCallbacks

0 commit comments

Comments
 (0)