diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-01-13 11:30:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-13 11:30:27 +0100 |
| commit | c2118d72d61746f2462fca695dbf3adf44ebf8f7 (patch) | |
| tree | d1891d1801cc59f2ea8294a8ae5857fd414f15b6 /django/test | |
| parent | 648005dee62481acc1784e5c9625e90f0fd6aab4 (diff) | |
Fixed #34240 -- Preserved headers of requests made with django.test.Client in assertRedirects().
Bug in 67da22f08e05018ea968fcacbac9ac37ea925d85.
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 10 | ||||
| -rw-r--r-- | django/test/testcases.py | 2 |
2 files changed, 12 insertions, 0 deletions
diff --git a/django/test/client.py b/django/test/client.py index c303ca3d74..66a08a8117 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -845,6 +845,7 @@ class Client(ClientMixin, RequestFactory): self.raise_request_exception = raise_request_exception self.exc_info = None self.extra = None + self.headers = None def request(self, **request): """ @@ -905,6 +906,7 @@ class Client(ClientMixin, RequestFactory): ): """Request a response from the server using GET.""" self.extra = extra + self.headers = headers response = super().get(path, data=data, secure=secure, headers=headers, **extra) if follow: response = self._handle_redirects( @@ -925,6 +927,7 @@ class Client(ClientMixin, RequestFactory): ): """Request a response from the server using POST.""" self.extra = extra + self.headers = headers response = super().post( path, data=data, @@ -951,6 +954,7 @@ class Client(ClientMixin, RequestFactory): ): """Request a response from the server using HEAD.""" self.extra = extra + self.headers = headers response = super().head( path, data=data, secure=secure, headers=headers, **extra ) @@ -973,6 +977,7 @@ class Client(ClientMixin, RequestFactory): ): """Request a response from the server using OPTIONS.""" self.extra = extra + self.headers = headers response = super().options( path, data=data, @@ -1000,6 +1005,7 @@ class Client(ClientMixin, RequestFactory): ): """Send a resource to the server using PUT.""" self.extra = extra + self.headers = headers response = super().put( path, data=data, @@ -1027,6 +1033,7 @@ class Client(ClientMixin, RequestFactory): ): """Send a resource to the server using PATCH.""" self.extra = extra + self.headers = headers response = super().patch( path, data=data, @@ -1054,6 +1061,7 @@ class Client(ClientMixin, RequestFactory): ): """Send a DELETE request to the server.""" self.extra = extra + self.headers = headers response = super().delete( path, data=data, @@ -1080,6 +1088,7 @@ class Client(ClientMixin, RequestFactory): ): """Send a TRACE request to the server.""" self.extra = extra + self.headers = headers response = super().trace( path, data=data, secure=secure, headers=headers, **extra ) @@ -1190,6 +1199,7 @@ class AsyncClient(ClientMixin, AsyncRequestFactory): self.raise_request_exception = raise_request_exception self.exc_info = None self.extra = None + self.headers = None async def request(self, **request): """ diff --git a/django/test/testcases.py b/django/test/testcases.py index 090a31e7c4..c29a13a710 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -545,10 +545,12 @@ class SimpleTestCase(unittest.TestCase): # Get the redirection page, using the same client that was used # to obtain the original response. extra = response.client.extra or {} + headers = response.client.headers or {} redirect_response = response.client.get( path, QueryDict(query), secure=(scheme == "https"), + headers=headers, **extra, ) self.assertEqual( |
