Skip to content
Myr

add unit test for api.request

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Daniel Schauenberg · committed by Daniel Schauenberg · parent f996313 · Browse files · 1 file+39 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+39 added−0 removed

  • tests:+39 added−0 removed

1 file+39 added−0 removed

modified:tests/unit/test_requests_api.py+39 added
24 unmodified lines
25 """Teardown."""26 pass272829 @mock.patch('requests.api.dispatch_hook')30 @mock.patch('requests.api.Request')31 @mock.patch('requests.api.cookiejar_from_dict')32 def test_request(self, mock_cjar, mock_request, mock_hook):33 args = dict(34 method = None,35 url = None,36 data = None,37 params = None,38 headers = None,39 cookiejar = None,40 files = None,41 auth = None,42 timeout = 1,43 allow_redirects = None,44 proxies = None,45 )46 hooks = {'args': args, 'pre_request': mock_request,47 'post_request': mock_request, 'response': 'response'}48 sideeffect = lambda x,y,z: hooks[x]49 mock_cjar.return_value = None50 mock_request.send = mock.Mock(return_value={})51 mock_request.response = "response"52 mock_hook.side_effect = sideeffect5354 r = requests.request('get','http://google.com')555657 mock_cjar.assert_called_once_with({})58 mock_hook.assert_called__with('args', None, args)59 mock_request.assert_called_once_with(**args)60 mock_hook.assert_called__with('pre_request', None, mock_request)61 mock_request.send.assert_called_once_with()62 mock_hook.assert_called__with('post_request', None, mock_request)63 mock_hook.assert_called__with('response', None, mock_request)64 self.assertEqual(r, "response")65666768 @mock.patch('requests.api.request')69 def test_http_get(self, mock_request):70 mock_request.return_value = Response()71 requests.get('http://google.com')
39 unmodified lines