summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-04-28 18:41:16 -0400
committerTim Graham <timograham@gmail.com>2014-04-28 18:41:36 -0400
commitaabceadd7d7a61468b0dc7dc9d560a770abae0cf (patch)
treebf8997b7ecdb1e2c72b8a8db1d90eb20be53fc56
parent26b03f25265227498a2559af807918fe2a1d246f (diff)
Revert "Fixed #15179 -- middlewares not applied for test client login()"
This reverts commit 4fdd51b73240bf9c8d9472fcc45df699f0714755. See the ticket for concerns with this implementation; it will be revisited.
-rw-r--r--django/test/client.py9
-rw-r--r--docs/releases/1.7.txt5
-rw-r--r--docs/topics/testing/tools.txt14
-rw-r--r--tests/test_client_regress/tests.py44
4 files changed, 4 insertions, 68 deletions
diff --git a/django/test/client.py b/django/test/client.py
index e6a9593dfd..9513dcd809 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -15,7 +15,7 @@ from django.core.handlers.wsgi import WSGIRequest
from django.core.signals import (request_started, request_finished,
got_request_exception)
from django.db import close_old_connections
-from django.http import SimpleCookie, QueryDict
+from django.http import SimpleCookie, HttpRequest, QueryDict
from django.template import TemplateDoesNotExist
from django.test import signals
from django.utils.functional import curry
@@ -553,8 +553,8 @@ class Client(RequestFactory):
apps.is_installed('django.contrib.sessions')):
engine = import_module(settings.SESSION_ENGINE)
- # Create a fake request that goes through request middleware
- request = self.request().wsgi_request
+ # Create a fake request to store login details.
+ request = HttpRequest()
if self.session:
request.session = self.session
@@ -588,9 +588,8 @@ class Client(RequestFactory):
Causes the authenticated user to be logged out.
"""
from django.contrib.auth import get_user_model, logout
- # Create a fake request that goes through request middleware
- request = self.request().wsgi_request
+ request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
UserModel = get_user_model()
if self.session:
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index 7357fe0bfb..3cd832e750 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -802,11 +802,6 @@ Tests
:class:`~django.test.Client`. If ``True``, the request will be made
through HTTPS.
-* Requests made with :meth:`Client.login() <django.test.Client.login>` and
- :meth:`Client.logout() <django.test.Client.logout>` respect defaults defined
- in :class:`~django.test.Client` instantiation and are processed through
- middleware.
-
* :meth:`~django.test.TransactionTestCase.assertNumQueries` now prints
out the list of executed queries if the assertion fails.
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 883bfaf9cd..c41e35d647 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -360,13 +360,6 @@ Use the ``django.test.Client`` class to make requests.
:meth:`~django.contrib.auth.models.UserManager.create_user` helper
method to create a new user with a correctly hashed password.
- .. versionadded:: 1.7
-
- Requests made with :meth:`~django.test.Client.login` go through the
- request middleware. If you need to control the environment, you can
- do so at :class:`~django.test.Client` instantiation or with the
- `Client.defaults` attribute.
-
.. method:: Client.logout()
If your site uses Django's :doc:`authentication system</topics/auth/index>`,
@@ -377,13 +370,6 @@ Use the ``django.test.Client`` class to make requests.
and session data cleared to defaults. Subsequent requests will appear
to come from an :class:`~django.contrib.auth.models.AnonymousUser`.
- .. versionadded:: 1.7
-
- Requests made with :meth:`~django.test.Client.logout` go through the
- request middleware. If you need to control the environment, you can
- do so at :class:`~django.test.Client` instantiation or with the
- `Client.defaults` attribute.
-
Testing responses
~~~~~~~~~~~~~~~~~
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index da903dfcfd..a776d10f20 100644
--- a/tests/test_client_regress/tests.py
+++ b/tests/test_client_regress/tests.py
@@ -7,7 +7,6 @@ from __future__ import unicode_literals
import os
import itertools
-from django.conf import settings
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template import (TemplateSyntaxError,
Context, Template, loader)
@@ -804,11 +803,6 @@ class AssertFormsetErrorTests(TestCase):
**kwargs)
-class ProcessedMiddleware(object):
- def process_request(self, request):
- request.has_been_processed = True
-
-
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
ROOT_URLCONF='test_client_regress.urls',)
class LoginTests(TestCase):
@@ -830,24 +824,6 @@ class LoginTests(TestCase):
# default client.
self.assertRedirects(response, "http://testserver/get_view/")
- @override_settings(
- MIDDLEWARE_CLASSES=list(settings.MIDDLEWARE_CLASSES) +
- ['test_client_regress.tests.ProcessedMiddleware'])
- def test_request_middleware(self):
- "Check that the request middleware is executed on login request"
-
- def listener(sender, signal, **kwargs):
- request = kwargs['request']
- self.assertTrue(hasattr(request, 'has_been_processed'))
-
- # Unlike other Client request performing methods, login and logout don't
- # return the response, therefore we must use signals to get it
- user_logged_in.connect(listener)
- try:
- self.client.login(username='testclient', password='password')
- finally:
- user_logged_in.disconnect(listener)
-
@override_settings(
PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
@@ -1348,32 +1324,12 @@ class UploadedFileEncodingTest(TestCase):
@override_settings(ROOT_URLCONF='test_client_regress.urls',)
class RequestHeadersTest(TestCase):
- fixtures = ['testdata']
-
def test_client_headers(self):
"A test client can receive custom headers"
response = self.client.get("/check_headers/", HTTP_X_ARG_CHECK='Testing 123')
self.assertEqual(response.content, b"HTTP_X_ARG_CHECK: Testing 123")
self.assertEqual(response.status_code, 200)
- @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
- def test_client_login_headers(self):
- "Test client headers are used in login"
-
- client = Client(HTTP_HOST='different')
-
- def listener(sender, signal, **kwargs):
- request = kwargs['request']
- self.assertEqual(request.get_host(), 'different')
-
- # Unlike other Client request performing methods, login and logout don't
- # return the response, therefore we must use signals to get it
- user_logged_in.connect(listener)
- try:
- client.login(username='testclient', password='password')
- finally:
- user_logged_in.disconnect(listener)
-
def test_client_headers_redirect(self):
"Test client headers are preserved through redirects"
response = self.client.get("/check_headers_redirect/", follow=True, HTTP_X_ARG_CHECK='Testing 123')