From: Ian Cordasco Date: Tue, 8 Oct 2013 02:17:46 +0000 (-0500) Subject: Add tests around hook behaviour X-Git-Tag: v2.1.0~10^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f12584b94ae06d48ce4125de4d29feb283d2d62c;p=services%2Fpython-requests.git Add tests around hook behaviour --- 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