]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Remove deprecated `allow_redirects` argument from `TestClient` (#2808)
authorRenan Heckert Leal <123672970+lealre@users.noreply.github.com>
Wed, 25 Dec 2024 08:45:38 +0000 (08:45 +0000)
committerGitHub <noreply@github.com>
Wed, 25 Dec 2024 08:45:38 +0000 (09:45 +0100)
pyproject.toml
starlette/testclient.py
tests/middleware/test_https_redirect.py
tests/test_responses.py

index f27646083821d3a0e02d4c1706912e5a9c73261d..18b954c844f7bb2e9f175af0ef3787fa17014299 100644 (file)
@@ -87,7 +87,6 @@ filterwarnings = [
     "ignore: Async generator 'starlette.requests.Request.stream' was garbage collected before it had been exhausted.*:ResourceWarning",
     "ignore: path is deprecated.*:DeprecationWarning:certifi",
     "ignore: Use 'content=<...>' to upload raw bytes/text content.:DeprecationWarning",
-    "ignore: The `allow_redirects` argument is deprecated. Use `follow_redirects` instead.:DeprecationWarning",
     "ignore: 'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning",
     "ignore: You seem to already have a custom sys.excepthook handler installed. I'll skip installing Trio's custom handler, but this means MultiErrors will not show full tracebacks.:RuntimeWarning",
     # TODO: This warning appeared when we bumped anyio to 4.4.0.
index 645ca10900a64658d5e76c80807d476bf2e45c6b..2c096aa226b88a4d87ea4a7df787e70dc26c21f7 100644 (file)
@@ -8,7 +8,6 @@ import math
 import queue
 import sys
 import typing
-import warnings
 from concurrent.futures import Future
 from functools import cached_property
 from types import GeneratorType
@@ -445,22 +444,6 @@ class TestClient(httpx.Client):
             with anyio.from_thread.start_blocking_portal(**self.async_backend) as portal:
                 yield portal
 
-    def _choose_redirect_arg(
-        self, follow_redirects: bool | None, allow_redirects: bool | None
-    ) -> bool | httpx._client.UseClientDefault:
-        redirect: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT
-        if allow_redirects is not None:
-            message = "The `allow_redirects` argument is deprecated. Use `follow_redirects` instead."
-            warnings.warn(message, DeprecationWarning)
-            redirect = allow_redirects
-        if follow_redirects is not None:
-            redirect = follow_redirects
-        elif allow_redirects is not None and follow_redirects is not None:
-            raise RuntimeError(  # pragma: no cover
-                "Cannot use both `allow_redirects` and `follow_redirects`."
-            )
-        return redirect
-
     def request(  # type: ignore[override]
         self,
         method: str,
@@ -474,13 +457,11 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
         url = self._merge_url(url)
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().request(
             method,
             url,
@@ -492,7 +473,7 @@ class TestClient(httpx.Client):
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -505,19 +486,17 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().get(
             url,
             params=params,
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -530,19 +509,17 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().options(
             url,
             params=params,
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -555,19 +532,17 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().head(
             url,
             params=params,
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -584,12 +559,10 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().post(
             url,
             content=content,
@@ -600,7 +573,7 @@ class TestClient(httpx.Client):
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -617,12 +590,10 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().put(
             url,
             content=content,
@@ -633,7 +604,7 @@ class TestClient(httpx.Client):
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -650,12 +621,10 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().patch(
             url,
             content=content,
@@ -666,7 +635,7 @@ class TestClient(httpx.Client):
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
@@ -679,19 +648,17 @@ class TestClient(httpx.Client):
         headers: httpx._types.HeaderTypes | None = None,
         cookies: httpx._types.CookieTypes | None = None,
         auth: httpx._types.AuthTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
-        follow_redirects: bool | None = None,
-        allow_redirects: bool | None = None,
+        follow_redirects: bool | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         timeout: httpx._types.TimeoutTypes | httpx._client.UseClientDefault = httpx._client.USE_CLIENT_DEFAULT,
         extensions: dict[str, typing.Any] | None = None,
     ) -> httpx.Response:
-        redirect = self._choose_redirect_arg(follow_redirects, allow_redirects)
         return super().delete(
             url,
             params=params,
             headers=headers,
             cookies=cookies,
             auth=auth,
-            follow_redirects=redirect,
+            follow_redirects=follow_redirects,
             timeout=timeout,
             extensions=extensions,
         )
index 22dfc14b65bd5773aeb86e9254242c4c574e90ae..66014e7e55c606ef99245813f81b05f5a6be25cd 100644 (file)
@@ -21,21 +21,21 @@ def test_https_redirect_middleware(test_client_factory: TestClientFactory) -> No
     assert response.status_code == 200
 
     client = test_client_factory(app)
-    response = client.get("/", allow_redirects=False)
+    response = client.get("/", follow_redirects=False)
     assert response.status_code == 307
     assert response.headers["location"] == "https://testserver/"
 
     client = test_client_factory(app, base_url="http://testserver:80")
-    response = client.get("/", allow_redirects=False)
+    response = client.get("/", follow_redirects=False)
     assert response.status_code == 307
     assert response.headers["location"] == "https://testserver/"
 
     client = test_client_factory(app, base_url="http://testserver:443")
-    response = client.get("/", allow_redirects=False)
+    response = client.get("/", follow_redirects=False)
     assert response.status_code == 307
     assert response.headers["location"] == "https://testserver/"
 
     client = test_client_factory(app, base_url="http://testserver:123")
-    response = client.get("/", allow_redirects=False)
+    response = client.get("/", follow_redirects=False)
     assert response.status_code == 307
     assert response.headers["location"] == "https://testserver:123/"
index 3c2d346d35de05250cc326b0e45a71ad8c7d89b7..9f801419a2bd98b86e3ead0c46be5a48c73d398c 100644 (file)
@@ -89,7 +89,7 @@ def test_redirect_response_content_length_header(
         await response(scope, receive, send)
 
     client: TestClient = test_client_factory(app)
-    response = client.request("GET", "/redirect", allow_redirects=False)
+    response = client.request("GET", "/redirect", follow_redirects=False)
     assert response.url == "http://testserver/redirect"
     assert response.headers["content-length"] == "0"