From e91deca7798139fa85a17e949aafd380af8fce13 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 4 May 2009 07:05:44 +0000 Subject: [PATCH] Fixed #10521 -- Modified the Remote User tests so that it isn't dependent 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 --- django/contrib/auth/tests/remote_user.py | 21 +++++++++++---------- django/contrib/auth/tests/urls.py | 9 +++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/django/contrib/auth/tests/remote_user.py b/django/contrib/auth/tests/remote_user.py index 449216d1eb9..842d589a54d 100644 --- a/django/contrib/auth/tests/remote_user.py +++ b/django/contrib/auth/tests/remote_user.py @@ -8,6 +8,7 @@ from django.test import TestCase 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 @@ class RemoteUserTest(TestCase): """ 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 @@ class RemoteUserTest(TestCase): 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 @@ class RemoteUserTest(TestCase): 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 @@ class RemoteUserTest(TestCase): 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 RemoteUserNoCreateTest(RemoteUserTest): 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) diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py index 492d1c74f4a..f94b8daa7f4 100644 --- a/django/contrib/auth/tests/urls.py +++ b/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), )