summaryrefslogtreecommitdiff
path: root/tests/auth_tests/test_views.py
diff options
context:
space:
mode:
authorAndrew Nester <andrew.nester.dev@gmail.com>2016-07-20 19:32:19 +0300
committerTim Graham <timograham@gmail.com>2016-07-22 15:04:13 -0400
commitdde6288fbe97c7053e67b613fec3366f3c298cf4 (patch)
tree304b68bdb5ede6898a0fe14bfdb92afa236c0cc2 /tests/auth_tests/test_views.py
parentcaa006f3275b8bdd1b26656291aa55ef6465ce61 (diff)
Fixed #26882 -- Added tests for auth.views.logout_then_login().
Diffstat (limited to 'tests/auth_tests/test_views.py')
-rw-r--r--tests/auth_tests/test_views.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index bd01c67d70..32c51e41a0 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -15,7 +15,9 @@ from django.contrib.auth.forms import (
AuthenticationForm, PasswordChangeForm, SetPasswordForm,
)
from django.contrib.auth.models import User
-from django.contrib.auth.views import LoginView, redirect_to_login
+from django.contrib.auth.views import (
+ LoginView, logout_then_login, redirect_to_login,
+)
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.sites.requests import RequestSite
from django.core import mail
@@ -707,6 +709,32 @@ class RedirectToLoginTests(AuthViewsTestCase):
self.assertEqual(expected, login_redirect_response.url)
+class LogoutThenLoginTests(AuthViewsTestCase):
+ """Tests for the logout_then_login view"""
+
+ def confirm_logged_out(self):
+ self.assertNotIn(SESSION_KEY, self.client.session)
+
+ @override_settings(LOGIN_URL='/login/')
+ def test_default_logout_then_login(self):
+ self.login()
+ req = HttpRequest()
+ req.method = 'GET'
+ req.session = self.client.session
+ response = logout_then_login(req)
+ self.confirm_logged_out()
+ self.assertRedirects(response, '/login/', fetch_redirect_response=False)
+
+ def test_logout_then_login_with_custom_login(self):
+ self.login()
+ req = HttpRequest()
+ req.method = 'GET'
+ req.session = self.client.session
+ response = logout_then_login(req, login_url='/custom/')
+ self.confirm_logged_out()
+ self.assertRedirects(response, '/custom/', fetch_redirect_response=False)
+
+
class LoginRedirectAuthenticatedUser(AuthViewsTestCase):
dont_redirect_url = '/login/redirect_authenticated_user_default/'
do_redirect_url = '/login/redirect_authenticated_user/'