Пример #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')
Пример #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)
Пример #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')
Пример #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)
Пример #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')
Пример #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)
Пример #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)
Пример #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()
Пример #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()
Пример #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)
Пример #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')