mirror of https://github.com/scrapy/scrapy.git
test #22 Improve json_request.py coverage
This commit is contained in:
parent
ba8993ec09
commit
12b4417c56
|
|
@ -1642,6 +1642,26 @@ class JsonRequestTest(RequestTest):
|
|||
self.assertEqual(kwargs["ensure_ascii"], True)
|
||||
self.assertEqual(kwargs["allow_nan"], True)
|
||||
|
||||
def test_replacement_both_body_and_data_warns(self):
|
||||
"""Test that we can get a warning if both body and data are passed for branch coverage"""
|
||||
body1 = None
|
||||
body2 = b"body"
|
||||
data1 = {
|
||||
"name1": "value1",
|
||||
}
|
||||
data2 = {
|
||||
"name2": "value2",
|
||||
}
|
||||
r1 = self.request_class(url="http://www.example.com/", data=data1, body=body1)
|
||||
|
||||
with mock.patch("warnings.warn") as mock_warn:
|
||||
r1.replace(data=data2, body=body2)
|
||||
mock_warn.assert_called_once()
|
||||
(warning_message,), _ = mock_warn.call_args
|
||||
self.assertIn(
|
||||
"Both body and data passed. data will be ignored", warning_message
|
||||
)
|
||||
|
||||
def tearDown(self):
|
||||
warnings.resetwarnings()
|
||||
super().tearDown()
|
||||
|
|
|
|||
Loading…
Reference in New Issue