Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #10521 -- Modified the Remote User tests so that it isn't depen…

…dent on particular deployed URLs. Thanks to Kegan and Ramiro Morales for their contributions.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10674 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e91deca7798139fa85a17e949aafd380af8fce13 1 parent 6acfa88
@freakboy3742 freakboy3742 authored
View
21 django/contrib/auth/tests/remote_user.py
@@ -8,6 +8,7 @@
class RemoteUserTest(TestCase):
+ urls = 'django.contrib.auth.tests.urls'
middleware = 'django.contrib.auth.middleware.RemoteUserMiddleware'
backend = 'django.contrib.auth.backends.RemoteUserBackend'
@@ -28,15 +29,15 @@ def test_no_remote_user(self):
"""
num_users = User.objects.count()
- response = self.client.get('/')
+ response = self.client.get('/remote_user/')
self.assert_(isinstance(response.context['user'], AnonymousUser))
self.assertEqual(User.objects.count(), num_users)
- response = self.client.get('/', REMOTE_USER=None)
+ response = self.client.get('/remote_user/', REMOTE_USER=None)
self.assert_(isinstance(response.context['user'], AnonymousUser))
self.assertEqual(User.objects.count(), num_users)
- response = self.client.get('/', REMOTE_USER='')
+ response = self.client.get('/remote_user/', REMOTE_USER='')
self.assert_(isinstance(response.context['user'], AnonymousUser))
self.assertEqual(User.objects.count(), num_users)
@@ -46,13 +47,13 @@ def test_unknown_user(self):
as a User.
"""
num_users = User.objects.count()
- response = self.client.get('/', REMOTE_USER='newuser')
+ response = self.client.get('/remote_user/', REMOTE_USER='newuser')
self.assertEqual(response.context['user'].username, 'newuser')
self.assertEqual(User.objects.count(), num_users + 1)
User.objects.get(username='newuser')
# Another request with same user should not create any new users.
- response = self.client.get('/', REMOTE_USER='newuser')
+ response = self.client.get('/remote_user/', REMOTE_USER='newuser')
self.assertEqual(User.objects.count(), num_users + 1)
def test_known_user(self):
@@ -62,12 +63,12 @@ def test_known_user(self):
User.objects.create(username='knownuser')
User.objects.create(username='knownuser2')
num_users = User.objects.count()
- response = self.client.get('/', REMOTE_USER=self.known_user)
+ response = self.client.get('/remote_user/', REMOTE_USER=self.known_user)
self.assertEqual(response.context['user'].username, 'knownuser')
self.assertEqual(User.objects.count(), num_users)
# Test that a different user passed in the headers causes the new user
# to be logged in.
- response = self.client.get('/', REMOTE_USER=self.known_user2)
+ response = self.client.get('/remote_user/', REMOTE_USER=self.known_user2)
self.assertEqual(response.context['user'].username, 'knownuser2')
self.assertEqual(User.objects.count(), num_users)
@@ -82,13 +83,13 @@ def test_last_login(self):
user.last_login = default_login
user.save()
- response = self.client.get('/', REMOTE_USER=self.known_user)
+ response = self.client.get('/remote_user/', REMOTE_USER=self.known_user)
self.assertNotEqual(default_login, response.context['user'].last_login)
user = User.objects.get(username='knownuser')
user.last_login = default_login
user.save()
- response = self.client.get('/', REMOTE_USER=self.known_user)
+ response = self.client.get('/remote_user/', REMOTE_USER=self.known_user)
self.assertEqual(default_login, response.context['user'].last_login)
def tearDown(self):
@@ -113,7 +114,7 @@ class that doesn't create unknown users.
def test_unknown_user(self):
num_users = User.objects.count()
- response = self.client.get('/', REMOTE_USER='newuser')
+ response = self.client.get('/remote_user/', REMOTE_USER='newuser')
self.assert_(isinstance(response.context['user'], AnonymousUser))
self.assertEqual(User.objects.count(), num_users)
View
9 django/contrib/auth/tests/urls.py
@@ -1,9 +1,18 @@
from django.conf.urls.defaults import patterns
from django.contrib.auth.urls import urlpatterns
+from django.http import HttpResponse
+from django.template import Template, RequestContext
+
+def remote_user_auth_view(request):
+ "Dummy view for remote user tests"
+ t = Template("Username is {{ user }}.")
+ c = RequestContext(request, {})
+ return HttpResponse(t.render(c))
# special urls for auth test cases
urlpatterns += patterns('',
(r'^logout/custom_query/$', 'django.contrib.auth.views.logout', dict(redirect_field_name='follow')),
(r'^logout/next_page/$', 'django.contrib.auth.views.logout', dict(next_page='/somewhere/')),
+ (r'^remote_user/$', remote_user_auth_view),
)
Please sign in to comment.
Something went wrong with that request. Please try again.