Ejemplo n.º 1
0
 def test_geturl_retries(self):
     fp = BytesIO(b'')
     resp = HTTPResponse(fp, request_url='http://example.com')
     request_histories = [
         RequestHistory(method='GET', url='http://example.com', error=None,
                        status=301, redirect_location='https://example.com/'),
         RequestHistory(method='GET', url='https://example.com/', error=None,
                        status=301, redirect_location='https://www.example.com')]
     retry = Retry(history=request_histories)
     resp = HTTPResponse(fp, retries=retry)
     assert resp.geturl() == 'https://www.example.com'
Ejemplo n.º 2
0
 def test_retry_redirect_history(self):
     with HTTPConnectionPool(self.host, self.port) as pool:
         resp = pool.request("GET", "/redirect", fields={"target": "/"})
         assert resp.status == 200
         assert resp.retries.history == (
             RequestHistory("GET", "/redirect?target=%2F", None, 303, "/"),
         )
Ejemplo n.º 3
0
 def test_retry_redirect_history(self):
     resp = self.pool.request("GET", "/redirect", fields={"target": "/"})
     self.assertEqual(resp.status, 200)
     self.assertEqual(
         resp.retries.history,
         (RequestHistory("GET", "/redirect?target=%2F", None, 303, "/"), ),
     )
Ejemplo n.º 4
0
 def test_retry_return_in_response(self):
     headers = {'test-name': 'test_retry_return_in_response'}
     retry = Retry(total=2, status_forcelist=[418])
     resp = self.pool.request('GET', '/successful_retry',
                              headers=headers, retries=retry)
     self.assertEqual(resp.status, 200)
     self.assertEqual(resp.retries.total, 1)
     self.assertEqual(resp.retries.history, (RequestHistory('GET', '/successful_retry', None, 418, None),))
Ejemplo n.º 5
0
 def test_retry_redirect_history(self):
     with PoolManager() as http:
         resp = http.request("GET",
                             "%s/redirect" % self.base_url,
                             fields={"target": "/"})
         assert resp.status == 200
         assert resp.retries.history == (RequestHistory(
             "GET", self.base_url + "/redirect?target=%2F", None, 303,
             "/"), )
Ejemplo n.º 6
0
 def test_retry_redirect_history(self):
     with PoolManager() as http:
         resp = http.request('GET',
                             '%s/redirect' % self.base_url,
                             fields={'target': '/'})
         self.assertEqual(resp.status, 200)
         self.assertEqual(
             resp.retries.history,
             (RequestHistory('GET', self.base_url + '/redirect?target=%2F',
                             None, 303, '/'), ))
Ejemplo n.º 7
0
    def test_retry_return_in_response(self):
        headers = {'test-name': 'test_retry_return_in_response'}
        retry = Retry(total=2, status_forcelist=[418])

        with PoolManager() as http:
            resp = http.request('GET', '%s/successful_retry' % self.base_url,
                                headers=headers, retries=retry)
            self.assertEqual(resp.status, 200)
            self.assertEqual(resp.retries.total, 1)
            self.assertEqual(resp.retries.history,
                             (RequestHistory('GET', '/successful_retry', None, 418, None),))
Ejemplo n.º 8
0
 def test_retry_return_in_response(self):
     with HTTPConnectionPool(self.host, self.port) as pool:
         headers = {"test-name": "test_retry_return_in_response"}
         retry = Retry(total=2, status_forcelist=[418])
         resp = pool.request(
             "GET", "/successful_retry", headers=headers, retries=retry
         )
         assert resp.status == 200
         assert resp.retries.total == 1
         assert resp.retries.history == (
             RequestHistory("GET", "/successful_retry", None, 418, None),
         )
Ejemplo n.º 9
0
    def test_history(self):
        retry = Retry(total=10, method_whitelist=frozenset(["GET", "POST"]))
        assert retry.history == tuple()
        connection_error = ConnectTimeoutError("conntimeout")
        retry = retry.increment("GET", "/test1", None, connection_error)
        history = (RequestHistory("GET", "/test1", connection_error, None,
                                  None), )
        assert retry.history == history

        read_error = ReadTimeoutError(None, "/test2", "read timed out")
        retry = retry.increment("POST", "/test2", None, read_error)
        history = (
            RequestHistory("GET", "/test1", connection_error, None, None),
            RequestHistory("POST", "/test2", read_error, None, None),
        )
        assert retry.history == history

        response = HTTPResponse(status=500)
        retry = retry.increment("GET", "/test3", response, None)
        history = (
            RequestHistory("GET", "/test1", connection_error, None, None),
            RequestHistory("POST", "/test2", read_error, None, None),
            RequestHistory("GET", "/test3", None, 500, None),
        )
        assert retry.history == history
Ejemplo n.º 10
0
    def test_history(self) -> None:
        retry = Retry(total=10, allowed_methods=frozenset(["GET", "POST"]))
        assert retry.history == tuple()
        connection_error = ConnectTimeoutError("conntimeout")
        retry = retry.increment("GET", "/test1", None, connection_error)
        test_history1 = (RequestHistory("GET", "/test1", connection_error,
                                        None, None), )
        assert retry.history == test_history1

        read_error = ReadTimeoutError(DUMMY_POOL, "/test2", "read timed out")
        retry = retry.increment("POST", "/test2", None, read_error)
        test_history2 = (
            RequestHistory("GET", "/test1", connection_error, None, None),
            RequestHistory("POST", "/test2", read_error, None, None),
        )
        assert retry.history == test_history2

        response = HTTPResponse(status=500)
        retry = retry.increment("GET", "/test3", response, None)
        test_history3 = (
            RequestHistory("GET", "/test1", connection_error, None, None),
            RequestHistory("POST", "/test2", read_error, None, None),
            RequestHistory("GET", "/test3", None, 500, None),
        )
        assert retry.history == test_history3
Ejemplo n.º 11
0
 def test_geturl_retries(self):
     fp = BytesIO(b"")
     resp = HTTPResponse(fp, request_url="http://example.com")
     request_histories = [
         RequestHistory(
             method="GET",
             url="http://example.com",
             error=None,
             status=301,
             redirect_location="https://example.com/",
         ),
         RequestHistory(
             method="GET",
             url="https://example.com/",
             error=None,
             status=301,
             redirect_location="https://www.example.com",
         ),
     ]
     retry = Retry(history=request_histories)
     resp = HTTPResponse(fp, retries=retry)
     assert resp.geturl() == "https://www.example.com"
Ejemplo n.º 12
0
 def test_retry_return_in_response(self):
     headers = {"test-name": "test_retry_return_in_response"}
     retry = Retry(total=2, status_forcelist=[418])
     resp = self.pool.request("GET",
                              "/successful_retry",
                              headers=headers,
                              retries=retry)
     self.assertEqual(resp.status, 200)
     self.assertEqual(resp.retries.total, 1)
     self.assertEqual(
         resp.retries.history,
         (RequestHistory("GET", "/successful_retry", None, 418, None), ),
     )
Ejemplo n.º 13
0
    def test_retry_return_in_response(self):
        headers = {"test-name": "test_retry_return_in_response"}
        retry = Retry(total=2, status_forcelist=[418])

        with PoolManager() as http:
            resp = http.request(
                "GET",
                "%s/successful_retry" % self.base_url,
                headers=headers,
                retries=retry,
            )
            assert resp.status == 200
            assert resp.retries.total == 1
            assert resp.retries.history == (RequestHistory(
                "GET", "/successful_retry", None, 418, None), )
Ejemplo n.º 14
0
 def test_history(self):
     retry = Retry(total=10)
     self.assertEqual(retry.history, tuple())
     connection_error = ConnectTimeoutError('conntimeout')
     retry = retry.increment('GET', '/test1', None, connection_error)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),))
     read_error = ReadTimeoutError(None, "/test2", "read timed out")
     retry = retry.increment('POST', '/test2', None, read_error)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
                                      RequestHistory('POST', '/test2', read_error, None, None)))
     response = HTTPResponse(status=500)
     retry = retry.increment('GET', '/test3', response, None)
     self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
                                      RequestHistory('POST', '/test2', read_error, None, None),
                                      RequestHistory('GET', '/test3', None, 500, None)))
Ejemplo n.º 15
0
 def test_retry_redirect_history(self):
     resp = self.pool.request('GET', '/redirect', fields={'target': '/'})
     self.assertEqual(resp.status, 200)
     self.assertEqual(
         resp.retries.history,
         (RequestHistory('GET', '/redirect?target=%2F', None, 303, '/'), ))
Ejemplo n.º 16
0
 def test_retry_redirect_history(self):
     resp = self.pool.request("GET", "/redirect", fields={"target": "/"})
     assert resp.status == 200
     assert resp.retries.history == (RequestHistory("GET",
                                                    "/redirect?target=%2F",
                                                    None, 303, "/"), )