diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-03 11:21:40 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-09-03 11:21:40 +0000 |
| commit | 3bf4ef0c77f80e2ed7fab298679ab0c5f28bc900 (patch) | |
| tree | 89e50ada1d950d35b2862754dca2ec3c10099ca0 /tests/regressiontests | |
| parent | afc6985267609d7782ec01817b051267fef48cd1 (diff) | |
Fixed #4988 -- In the test client, Added tracking of the client and request that caused a response so that the assertRedirects check can use the correct client when following a redirect. Well spotted, alex@gc-web.de.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6039 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/test_client_regress/models.py | 21 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/urls.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/views.py | 12 |
3 files changed, 33 insertions, 2 deletions
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index e85544f285..aa18a48852 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -212,7 +212,7 @@ class AssertFormErrorTests(TestCase): except AssertionError, e: self.assertEqual(str(e), "The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])") -class AssertFileUploadTests(TestCase): +class FileUploadTests(TestCase): def test_simple_upload(self): fd = open(os.path.join(os.path.dirname(__file__), "views.py")) post_data = { @@ -221,3 +221,22 @@ class AssertFileUploadTests(TestCase): } response = self.client.post('/test_client_regress/file_upload/', post_data) self.assertEqual(response.status_code, 200) + +class LoginTests(TestCase): + fixtures = ['testdata'] + + def test_login_different_client(self): + "Check that using a different test client doesn't violate authentication" + + # Create a second client, and log in. + c = Client() + login = c.login(username='testclient', password='password') + self.assertTrue(login, 'Could not log in') + + # Get a redirection page with the second client. + response = c.get("/test_client_regress/login_protected_redirect_view/") + + # At this points, the self.client isn't logged in. + # Check that assertRedirects uses the original client, not the + # default client. + self.assertRedirects(response, "/test_client_regress/get_view/") diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py index 160f9f992d..e771707f61 100644 --- a/tests/regressiontests/test_client_regress/urls.py +++ b/tests/regressiontests/test_client_regress/urls.py @@ -4,4 +4,6 @@ import views urlpatterns = patterns('', (r'^no_template_view/$', views.no_template_view), (r'^file_upload/$', views.file_upload_view), + (r'^get_view/$', views.get_view), + (r'^login_protected_redirect_view/$', views.login_protected_redirect_view) ) diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py index d3fbcf8448..75efd212e1 100644 --- a/tests/regressiontests/test_client_regress/views.py +++ b/tests/regressiontests/test_client_regress/views.py @@ -1,5 +1,6 @@ +from django.contrib.auth.decorators import login_required from django.core.mail import EmailMessage, SMTPConnection -from django.http import HttpResponse, HttpResponseServerError +from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError from django.shortcuts import render_to_response def no_template_view(request): @@ -18,3 +19,12 @@ def file_upload_view(request): else: return HttpResponseServerError() +def get_view(request): + "A simple login protected view" + return HttpResponse("Hello world") +get_view = login_required(get_view) + +def login_protected_redirect_view(request): + "A view that redirects all requests to the GET view" + return HttpResponseRedirect('/test_client_regress/get_view/') +login_protected_redirect_view = login_required(login_protected_redirect_view)
\ No newline at end of file |
