Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 19b9211a3b5424e7908a288c5008bf972cc472f4 1 parent e6ad4fb
@jacobian jacobian authored
View
3  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 @@
'FORM_TESTS': FORM_TESTS,
'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS,
'CHANGEPASSWORD_TESTS': ChangePasswordTest,
+ 'LOGIN_TESTS': LoginTest,
}
View
23 django/contrib/auth/tests/views.py
@@ -3,9 +3,12 @@
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 @@ def test_password_change_succeeds(self):
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')
+
View
1  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)
Please sign in to comment.
Something went wrong with that request. Please try again.