<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import mock
import sys
import os
sys.path.append(os.getcwd())

try:
    import omnijson as json
except ImportError:
    import json

import requests
from requests.models import Response

class RequestsAPIUnitTests(unittest.TestCase):
    """Requests API unit test cases."""

    def setUp(self):
        pass


    def tearDown(self):
        """Teardown."""
        pass


    @mock.patch('requests.api.dispatch_hook')
    @mock.patch('requests.api.Request')
    @mock.patch('requests.api.cookiejar_from_dict')
    def test_request(self, mock_cjar, mock_request, mock_hook):
        args = dict(
                    method = None,
                    url = None,
                    data = None,
                    params = None,
                    headers = None,
                    cookiejar = None,
                    files = None,
                    auth = None,
                    timeout = 1,
                    allow_redirects = None,
                    proxies = None,
                   )
        hooks = {'args': args, 'pre_request': mock_request,
                 'post_request': mock_request, 'response': 'response'}
        sideeffect = lambda x,y,z: hooks[x]
        mock_cjar.return_value = None
        mock_request.send = mock.Mock(return_value={})
        mock_request.response = "response"
        mock_hook.side_effect = sideeffect

        r = requests.request('get','http://google.com')


        mock_cjar.assert_called_once_with({})
        mock_hook.assert_called__with('args', None, args)
        mock_request.assert_called_once_with(**args)
        mock_hook.assert_called__with('pre_request', None, mock_request)
        mock_request.send.assert_called_once_with()
        mock_hook.assert_called__with('post_request', None, mock_request)
        mock_hook.assert_called__with('response', None, mock_request)
        self.assertEqual(r, "response")



    @mock.patch('requests.api.request')
    def test_http_get(self, mock_request):
        mock_request.return_value = Response()
        requests.get('http://google.com')
        mock_request.assert_called_once_with('get', 'http://google.com',
                                             allow_redirects= True)

    @mock.patch('requests.api.request')
    def test_http_get_with_kwargs(self, mock_request):
        mock_request.return_value = Response()
        requests.get('http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")
        mock_request.assert_called_once_with('get', 'http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")

    @mock.patch('requests.api.request')
    def test_http_head(self, mock_request):
        mock_request.return_value = Response()
        requests.head('http://google.com')
        mock_request.assert_called_once_with('head', 'http://google.com',
                                             allow_redirects= True)

    @mock.patch('requests.api.request')
    def test_http_post(self, mock_request):
        mock_request.return_value = Response()
        requests.post('http://google.com', {})
        mock_request.assert_called_once_with('post', 'http://google.com',
                                              data= {})

    @mock.patch('requests.api.request')
    def test_http_put(self, mock_request):
        mock_request.return_value = Response()
        requests.put('http://google.com', {})
        mock_request.assert_called_once_with('put', 'http://google.com',<commit_msg>add test with kwargs for api.head<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import mock
import sys
import os
sys.path.append(os.getcwd())

try:
    import omnijson as json
except ImportError:
    import json

import requests
from requests.models import Response

class RequestsAPIUnitTests(unittest.TestCase):
    """Requests API unit test cases."""

    def setUp(self):
        pass


    def tearDown(self):
        """Teardown."""
        pass


    @mock.patch('requests.api.dispatch_hook')
    @mock.patch('requests.api.Request')
    @mock.patch('requests.api.cookiejar_from_dict')
    def test_request(self, mock_cjar, mock_request, mock_hook):
        args = dict(
                    method = None,
                    url = None,
                    data = None,
                    params = None,
                    headers = None,
                    cookiejar = None,
                    files = None,
                    auth = None,
                    timeout = 1,
                    allow_redirects = None,
                    proxies = None,
                   )
        hooks = {'args': args, 'pre_request': mock_request,
                 'post_request': mock_request, 'response': 'response'}
        sideeffect = lambda x,y,z: hooks[x]
        mock_cjar.return_value = None
        mock_request.send = mock.Mock(return_value={})
        mock_request.response = "response"
        mock_hook.side_effect = sideeffect

        r = requests.request('get','http://google.com')


        mock_cjar.assert_called_once_with({})
        mock_hook.assert_called__with('args', None, args)
        mock_request.assert_called_once_with(**args)
        mock_hook.assert_called__with('pre_request', None, mock_request)
        mock_request.send.assert_called_once_with()
        mock_hook.assert_called__with('post_request', None, mock_request)
        mock_hook.assert_called__with('response', None, mock_request)
        self.assertEqual(r, "response")



    @mock.patch('requests.api.request')
    def test_http_get(self, mock_request):
        mock_request.return_value = Response()
        requests.get('http://google.com')
        mock_request.assert_called_once_with('get', 'http://google.com',
                                             allow_redirects= True)

    @mock.patch('requests.api.request')
    def test_http_get_with_kwargs(self, mock_request):
        mock_request.return_value = Response()
        requests.get('http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")
        mock_request.assert_called_once_with('get', 'http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")

    @mock.patch('requests.api.request')
    def test_http_head(self, mock_request):
        mock_request.return_value = Response()
        requests.head('http://google.com')
        mock_request.assert_called_once_with('head', 'http://google.com',
                                             allow_redirects= True)

    @mock.patch('requests.api.request')
    def test_http_head_with_kwargs(self, mock_request):
        mock_request.return_value = Response()
        requests.head('http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")
        mock_request.assert_called_once_with('head', 'http://google.com',
                     params="params", data="data", headers="headers",
                     cookies="cookies",
                     files="files", auth="auth", timeout="timeout",
                     allow_redirects=False,
                     proxies="proxies", hooks="hooks")

    def test_http_post(self, mock_request):
        mock_request.return_value = Response()
        requests.post('http://google.com', {})
        mock_request.assert_called_once_with('post', 'http://google.com',
                                              data= {})

    @mock.patch('requests.api.request')
    def test_http_put(self, mock_request):
        mock_request.return_value = Response()
        requests.put('http://google.com', {})
        mock_request.assert_called_once_with('put', 'http://google.com',
{'fraction_non_alphanumeric': 0.12272883099074391, 'fraction_numerical': 0.0004570906182150611, 'mean_word_length': 2.0687237026647964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5085951', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2334, 'n_words': 400}