Skip to content

Commit

Permalink
Fixed #9881: Added the to the login view context, not just the site's…
Browse files Browse the repository at this point in the history
… name. Thanks, nessita.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10330 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed Apr 1, 2009
1 parent e6ad4fb commit 19b9211
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion 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
Expand All @@ -14,4 +14,5 @@
'FORM_TESTS': FORM_TESTS,
'TOKEN_GENERATOR_TESTS': TOKEN_GENERATOR_TESTS,
'CHANGEPASSWORD_TESTS': ChangePasswordTest,
'LOGIN_TESTS': LoginTest,
}
23 changes: 23 additions & 0 deletions django/contrib/auth/tests/views.py
Expand Up @@ -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']
Expand Down Expand Up @@ -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')

1 change: 1 addition & 0 deletions django/contrib/auth/views.py
Expand Up @@ -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)
Expand Down

0 comments on commit 19b9211

Please sign in to comment.