Add pickle test with hooks

This commit is contained in:
Keyan Pishdadian
2015-09-23 21:45:35 -04:00
committed by Nate Prewitt
parent 117813ee2e
commit 647ed5b6de
+21
View File
@@ -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):