diff options
Diffstat (limited to 'django/contrib/auth/tests/views.py')
| -rw-r--r-- | django/contrib/auth/tests/views.py | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py index 754241d5d2..f2faf09228 100644 --- a/django/contrib/auth/tests/views.py +++ b/django/contrib/auth/tests/views.py @@ -1,8 +1,8 @@ - import os import re from django.conf import settings +from django.contrib.auth import SESSION_KEY from django.contrib.auth.forms import AuthenticationForm from django.contrib.sites.models import Site, RequestSite from django.contrib.auth.models import User @@ -184,4 +184,52 @@ class LoginTest(TestCase): self.assertEquals(response.context['site_name'], site.name) self.assert_(isinstance(response.context['form'], AuthenticationForm), 'Login form is not an AuthenticationForm') -
\ No newline at end of file + +class LogoutTest(TestCase): + fixtures = ['authtestdata.json'] + urls = 'django.contrib.auth.tests.urls' + + def login(self, password='password'): + response = self.client.post('/login/', { + 'username': 'testclient', + 'password': password + } + ) + self.assertEquals(response.status_code, 302) + self.assert_(response['Location'].endswith(settings.LOGIN_REDIRECT_URL)) + self.assert_(SESSION_KEY in self.client.session) + + def confirm_logged_out(self): + self.assert_(SESSION_KEY not in self.client.session) + + def test_logout_default(self): + "Logout without next_page option renders the default template" + self.login() + response = self.client.get('/logout/') + self.assertEquals(200, response.status_code) + self.assert_('Logged out' in response.content) + self.confirm_logged_out() + + def test_logout_with_next_page_specified(self): + "Logout with next_page option given redirects to specified resource" + self.login() + response = self.client.get('/logout/next_page/') + self.assertEqual(response.status_code, 302) + self.assert_(response['Location'].endswith('/somewhere/')) + self.confirm_logged_out() + + def test_logout_with_redirect_argument(self): + "Logout with query string redirects to specified resource" + self.login() + response = self.client.get('/logout/?next=/login/') + self.assertEqual(response.status_code, 302) + self.assert_(response['Location'].endswith('/login/')) + self.confirm_logged_out() + + def test_logout_with_custom_redirect_argument(self): + "Logout with custom query string redirects to specified resource" + self.login() + response = self.client.get('/logout/custom_query/?follow=/somewhere/') + self.assertEqual(response.status_code, 302) + self.assert_(response['Location'].endswith('/somewhere/')) + self.confirm_logged_out()
\ No newline at end of file |
