mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add pickle test with hooks
This commit is contained in:
committed by
Nate Prewitt
parent
117813ee2e
commit
647ed5b6de
@@ -1090,6 +1090,27 @@ class TestRequests:
|
||||
|
||||
assert r.status_code == 200
|
||||
|
||||
def test_prepared_request_with_hook_is_pickleable(self):
|
||||
def print_url(r, *args, **kwargs):
|
||||
print(r.url)
|
||||
|
||||
r = requests.Request('POST', httpbin('post'), hooks=dict(response=print_url))
|
||||
p = r.prepare()
|
||||
|
||||
# Verify we can pickle the request.
|
||||
assert pickle.dumps(p)
|
||||
r = pickle.dumps(p)
|
||||
|
||||
# Verify we can use the pickled request.
|
||||
assert pickle.loads(r)
|
||||
r = pickle.loads(r)
|
||||
|
||||
# Verify we can use the unpickled request.
|
||||
s = requests.Session()
|
||||
r = s.send(r)
|
||||
|
||||
assert r.status_code == 200
|
||||
|
||||
def test_cannot_send_unprepared_requests(self, httpbin):
|
||||
r = requests.Request(url=httpbin())
|
||||
with pytest.raises(ValueError):
|
||||
|
||||
Reference in New Issue
Block a user