From 647ed5b6de6a71d235eb222fe978899c0447b0f2 Mon Sep 17 00:00:00 2001 From: Keyan Pishdadian Date: Wed, 23 Sep 2015 21:45:35 -0400 Subject: [PATCH] Add pickle test with hooks --- tests/test_requests.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_requests.py b/tests/test_requests.py index f665fc25..1fd6d85b 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -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):