From 19b9211a3b5424e7908a288c5008bf972cc472f4 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Wed, 1 Apr 2009 16:37:48 +0000 Subject: [PATCH] Fixed #9881: Added the to the login view context, not just the site's name. Thanks, nessita. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10330 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/auth/tests/__init__.py | 3 ++- django/contrib/auth/tests/views.py | 23 +++++++++++++++++++++++ django/contrib/auth/views.py | 1 + 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py index e878d43a7b..bd86111586 100644 --- a/django/contrib/auth/tests/__init__.py +++ b/django/contrib/auth/tests/__init__.py @@ -1,6 +1,6 @@ from django.contrib.auth.tests.basic import BASIC_TESTS from django.contrib.auth.tests.views \ - import PasswordResetTest, ChangePasswordTest + import PasswordResetTest, ChangePasswordTest, LoginTest from django.contrib.auth.tests.forms import FORM_TESTS from django.contrib.auth.tests.remote_user \ import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest @@ -14,4 +14,5 @@ __test__ = { 'FORM_TESTS': FORM_TESTS, 'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS, 'CHANGEPASSWORD_TESTS': ChangePasswordTest, + 'LOGIN_TESTS': LoginTest, } diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py index 3e5cbabf05..754241d5d2 100644 --- a/django/contrib/auth/tests/views.py +++ b/django/contrib/auth/tests/views.py @@ -3,9 +3,12 @@ import os import re from django.conf import settings +from django.contrib.auth.forms import AuthenticationForm +from django.contrib.sites.models import Site, RequestSite from django.contrib.auth.models import User from django.test import TestCase from django.core import mail +from django.core.urlresolvers import reverse class PasswordResetTest(TestCase): fixtures = ['authtestdata.json'] @@ -162,3 +165,23 @@ class ChangePasswordTest(TestCase): self.fail_login() self.login(password='password1') +class LoginTest(TestCase): + fixtures = ['authtestdata.json'] + urls = 'django.contrib.auth.urls' + + def setUp(self): + self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS + settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),) + + def tearDown(self): + settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS + + def test_current_site_in_context_after_login(self): + response = self.client.get(reverse('django.contrib.auth.views.login')) + self.assertEquals(response.status_code, 200) + site = Site.objects.get_current() + self.assertEquals(response.context['site'], site) + 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 diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index e1f0d43c00..18572f1584 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -38,6 +38,7 @@ def login(request, template_name='registration/login.html', redirect_field_name= return render_to_response(template_name, { 'form': form, redirect_field_name: redirect_to, + 'site': current_site, 'site_name': current_site.name, }, context_instance=RequestContext(request)) login = never_cache(login)