Skip to content

Commit 84dac7d

Browse files
committed
update expectation for replacing zyte_api_response attribute
1 parent ba64103 commit 84dac7d

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

scrapy_zyte_api/responses.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ def __init__(self, *args, zyte_api_response: Dict = None, **kwargs):
1515
def replace(self, *args, **kwargs):
1616
"""Create a new response with the same attributes except for those given
1717
new values.
18-
19-
NOTE: This doesn't support replacing the ``zyte_api_response`` attribute.
2018
"""
21-
instance = super().replace(*args, **kwargs)
22-
instance._zyte_api_response = self.zyte_api_response
23-
return instance
19+
return super().replace(*args, **kwargs)
2420

2521
@property
2622
def zyte_api_response(self) -> Optional[Dict]:

tests/test_responses.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,29 @@ def test_text_from_api_response(api_response, cls):
9191
def test_response_replace(api_response, cls):
9292
orig_response = cls.from_api_response(api_response())
9393

94-
# The ``zyte_api_response`` should not be replaced.
95-
new_response = orig_response.replace(zyte_api_response={"overridden": "value"})
96-
assert new_response.zyte_api_response == orig_response.zyte_api_response
97-
9894
# It should still work the same way
9995
new_response = orig_response.replace(status=404)
10096
assert new_response.status == 404
101-
assert new_response.zyte_api_response == orig_response.zyte_api_response
97+
98+
new_response = orig_response.replace(url="https://new-example.com")
99+
assert new_response.url == "https://new-example.com"
100+
101+
102+
@pytest.mark.xfail
103+
@pytest.mark.parametrize(
104+
"api_response,cls",
105+
[
106+
(api_response_browser, ZyteAPITextResponse),
107+
(api_response_body, ZyteAPIResponse),
108+
],
109+
)
110+
def test_response_replace_zyte_api_response(api_response, cls):
111+
orig_response = cls.from_api_response(api_response())
112+
113+
# The ``zyte_api_response`` should not be replaced.
114+
new_zyte_api_response = {"overridden": "value"}
115+
new_response = orig_response.replace(zyte_api_response=new_zyte_api_response)
116+
assert new_response.zyte_api_response == api_response()
102117

103118

104119
def test_non_utf8_response():

0 commit comments

Comments
 (0)