Add correct defaults in Session.send()
authorIan Cordasco <graffatcolmingov@gmail.com>
Thu, 28 Mar 2013 03:17:34 +0000 (23:17 -0400)
committerIan Cordasco <graffatcolmingov@gmail.com>
Thu, 28 Mar 2013 03:17:34 +0000 (23:17 -0400)
Resolves #1258

Also fixed the tests to reflect the necessary changes.

requests/sessions.py
test_requests.py

index fe0a84e1e812b826d9f8c277349fa9c8d55d9d03..ab56464b4e5d92a3d006334ba0dc896651b2cd07 100644 (file)
@@ -316,7 +316,6 @@ class Session(SessionRedirectMixin):
             'cert': cert,
             'proxies': proxies,
             'allow_redirects': allow_redirects,
-            'req': req,
         }
         resp = self.send(prep, **send_kwargs)
 
@@ -398,14 +397,17 @@ class Session(SessionRedirectMixin):
         """Send a given PreparedRequest."""
         # It's possible that users might accidentally send a Request object.
         # Guard against that specific failure case.
+        kwargs.setdefault('stream', False)
+        kwargs.setdefault('verify', True)
+        kwargs.setdefault('proxies', {})
+
         if getattr(request, 'prepare', None):
             raise ValueError('You can only send PreparedRequests.')
 
         # Set up variables needed for resolve_redirects and dispatching of
         # hooks
         allow_redirects = kwargs.pop('allow_redirects', True)
-        req = kwargs.pop('req', None)
-        stream = kwargs.get('stream', False)
+        stream = kwargs.get('stream')
         timeout = kwargs.get('timeout')
         verify = kwargs.get('verify')
         cert = kwargs.get('cert')
index 64003cfc5b4d0413e8583fb17a3b4b88160d8f1d..93b81236d80d3819ee37739865b8f206eec4ddd5 100644 (file)
@@ -295,8 +295,15 @@ class RequestsTestCase(unittest.TestCase):
         self.assertEqual(r.status_code, 200)
         self.assertTrue(b"text/py-content-type" in r.request.body)
 
+    def test_hook_receives_request_arguments(self):
+        def hook(resp, **kwargs):
+            assert resp is not None
+            assert kwargs != {}
+
+        requests.Request('GET', HTTPBIN, hooks={'response': hook})
+
     def test_prepared_request_hook(self):
-        def hook(resp):
+        def hook(resp, **kwargs):
             resp.hook_working = True
             return resp