Beispiel #1
0
 def test_passthrough(self):
     requests.get('http://foo.com')
     self.session_request.assert_called_with(allow_redirects=True,
                                             method='get',
                                             params=None,
                                             timeout=(None, None),
                                             url='http://foo.com')
Beispiel #2
0
 def test_default_timeout(self):
     try:
         requests.set_default_timeout(5)
         requests.get('http://foo.com')
         self.session_request.assert_called_with(
             allow_redirects=True, method='get', params=None,
             timeout=(5, 5), url='http://foo.com')
     finally:
         requests.set_default_timeout(None)
Beispiel #3
0
    def test_timeout(self):
        requests.get('http://foo.com', timeout=10)
        self.session_request.assert_called_with(
            allow_redirects=True, method='get', params=None,
            timeout=10, url='http://foo.com')

        requests.get('http://foo.com', timeout=(10, 15))
        self.session_request.assert_called_with(
            allow_redirects=True, method='get', params=None,
            timeout=(10, 15), url='http://foo.com')
Beispiel #4
0
 def test_default_timeout(self):
     try:
         requests.set_default_timeout(5)
         requests.get('http://foo.com')
         self.session_request.assert_called_with(allow_redirects=True,
                                                 method='get',
                                                 params=None,
                                                 timeout=(5, 5),
                                                 url='http://foo.com')
     finally:
         requests.set_default_timeout(None)
Beispiel #5
0
    def test_timeout(self):
        requests.get('http://foo.com', timeout=10)
        self.session_request.assert_called_with(allow_redirects=True,
                                                method='get',
                                                params=None,
                                                timeout=10,
                                                url='http://foo.com')

        requests.get('http://foo.com', timeout=(10, 15))
        self.session_request.assert_called_with(allow_redirects=True,
                                                method='get',
                                                params=None,
                                                timeout=(10, 15),
                                                url='http://foo.com')
Beispiel #6
0
    def test_retries(self):
        requests.get('http://foo.com', retries=10)
        self.session_request.assert_called_with(
            allow_redirects=True, method='get', params=None,
            timeout=(None, None), url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.total, 10)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.total, 10)

        requests.get('http://foo.com', retries={'total': 5})
        self.session_request.assert_called_with(
            allow_redirects=True, method='get', params=None,
            timeout=(None, None), url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.total, 5)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.total, 5)

        requests.get('http://foo.com', retries={'read': 2,
                                                'backoff_factor': 2})
        self.session_request.assert_called_with(
            allow_redirects=True, method='get', params=None,
            timeout=(None, None), url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
Beispiel #7
0
    def test_retries(self):
        requests.get("http://foo.com", retries=10)
        self.session_request.assert_called_with(
            allow_redirects=True,
            method="get",
            params=None,
            timeout=(None, None),
            url="http://foo.com",
        )
        adapter = self._get_mount("http://")
        self.assertEqual(adapter.max_retries.total, 10)
        adapter = self._get_mount("https://")
        self.assertEqual(adapter.max_retries.total, 10)

        requests.get("http://foo.com", retries={"total": 5})
        self.session_request.assert_called_with(
            allow_redirects=True,
            method="get",
            params=None,
            timeout=(None, None),
            url="http://foo.com",
        )
        adapter = self._get_mount("http://")
        self.assertEqual(adapter.max_retries.total, 5)
        adapter = self._get_mount("https://")
        self.assertEqual(adapter.max_retries.total, 5)

        requests.get("http://foo.com",
                     retries={
                         "read": 2,
                         "backoff_factor": 2
                     })
        self.session_request.assert_called_with(
            allow_redirects=True,
            method="get",
            params=None,
            timeout=(None, None),
            url="http://foo.com",
        )
        adapter = self._get_mount("http://")
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
        adapter = self._get_mount("https://")
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
Beispiel #8
0
    def test_default_retries(self):
        try:
            requests.set_default_retries(3)
            requests.get("http://foo.com")
            adapter = self._get_mount("https://")
            self.assertEqual(adapter.max_retries.total, 3)

            requests.set_default_retries(total=3)
            requests.get("http://foo.com")
            adapter = self._get_mount("https://")
            self.assertEqual(adapter.max_retries.total, 3)

            requests.set_default_retries(connect=3)
            requests.get("http://foo.com")
            adapter = self._get_mount("https://")
            self.assertEqual(adapter.max_retries.connect, 3)
            self.assertEqual(adapter.max_retries.read, None)
        finally:
            requests.set_default_retries()
Beispiel #9
0
    def test_default_retries(self):
        try:
            requests.set_default_retries(3)
            requests.get('http://foo.com')
            adapter = self._get_mount('https://')
            self.assertEqual(adapter.max_retries.total, 3)

            requests.set_default_retries(total=3)
            requests.get('http://foo.com')
            adapter = self._get_mount('https://')
            self.assertEqual(adapter.max_retries.total, 3)

            requests.set_default_retries(connect=3)
            requests.get('http://foo.com')
            adapter = self._get_mount('https://')
            self.assertEqual(adapter.max_retries.connect, 3)
            self.assertEqual(adapter.max_retries.read, None)
        finally:
            requests.set_default_retries()
Beispiel #10
0
    def test_retries(self):
        requests.get('http://foo.com', retries=10)
        self.session_request.assert_called_with(allow_redirects=True,
                                                method='get',
                                                params=None,
                                                timeout=(None, None),
                                                url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.total, 10)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.total, 10)

        requests.get('http://foo.com', retries={'total': 5})
        self.session_request.assert_called_with(allow_redirects=True,
                                                method='get',
                                                params=None,
                                                timeout=(None, None),
                                                url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.total, 5)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.total, 5)

        requests.get('http://foo.com',
                     retries={
                         'read': 2,
                         'backoff_factor': 2
                     })
        self.session_request.assert_called_with(allow_redirects=True,
                                                method='get',
                                                params=None,
                                                timeout=(None, None),
                                                url='http://foo.com')
        adapter = self._get_mount('http://')
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
        adapter = self._get_mount('https://')
        self.assertEqual(adapter.max_retries.read, 2)
        self.assertEqual(adapter.max_retries.connect, None)
Beispiel #11
0
 def test_passthrough(self):
     requests.get('http://foo.com')
     self.session_request.assert_called_with(
         allow_redirects=True, method='get', params=None,
         timeout=(None, None), url='http://foo.com')