From f12584b94ae06d48ce4125de4d29feb283d2d62c Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Mon, 7 Oct 2013 21:17:46 -0500 Subject: [PATCH] Add tests around hook behaviour --- test_requests.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test_requests.py b/test_requests.py index d1e6ed0..0b6dddc 100755 --- a/test_requests.py +++ b/test_requests.py @@ -449,6 +449,25 @@ class RequestsTestCase(unittest.TestCase): requests.Request('GET', HTTPBIN, hooks={'response': hook}) + def test_session_hooks_are_used_with_no_request_hooks(self): + hook = lambda x, *args, **kwargs: x + s = requests.Session() + s.hooks['response'].append(hook) + r = requests.Request('GET', HTTPBIN) + prep = s.prepare_request(r) + assert prep.hooks['response'] != [] + assert prep.hooks['response'] == [hook] + + def test_session_hooks_are_overriden_by_request_hooks(self): + hook1 = lambda x, *args, **kwargs: x + hook2 = lambda x, *args, **kwargs: x + assert hook1 is not hook2 + s = requests.Session() + s.hooks['response'].append(hook2) + r = requests.Request('GET', HTTPBIN, hooks={'response': [hook1]}) + prep = s.prepare_request(r) + assert prep.hooks['response'] == [hook1] + def test_prepared_request_hook(self): def hook(resp, **kwargs): resp.hook_working = True -- 2.34.1