Changeset 7583
- Timestamp:
- 06/07/08 01:25:59 (4 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/test/client.py (modified) (1 diff)
- django/trunk/tests/modeltests/test_client/fixtures/testdata.json (modified) (1 diff)
- django/trunk/tests/regressiontests/test_client_regress/fixtures/testdata.json (modified) (1 diff)
- django/trunk/tests/regressiontests/test_client_regress/models.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/test_client_regress/urls.py (modified) (1 diff)
- django/trunk/tests/regressiontests/test_client_regress/views.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r7579 r7583 368 368 Vlado <vlado@labath.org> 369 369 Milton Waddams 370 Chris Wagner <cw264701@ohio.edu> 370 371 wam-djangobug@wamber.net 371 372 Wang Chun <wangchun@exoweb.net> django/trunk/django/test/client.py
r7577 r7583 180 180 raise 181 181 182 # Look for a signalled exception and reraise it 182 # Look for a signalled exception, clear the current context 183 # exception data, then re-raise the signalled exception. 184 # Also make sure that the signalled exception is cleared from 185 # the local cache! 183 186 if self.exc_info: 184 raise self.exc_info[1], None, self.exc_info[2] 185 187 exc_info = self.exc_info 188 self.exc_info = None 189 raise exc_info[1], None, exc_info[2] 190 186 191 # Save the client and request that stimulated the response 187 192 response.client = self django/trunk/tests/modeltests/test_client/fixtures/testdata.json
r5677 r7583 35 35 "date_joined": "2006-12-17 07:03:31" 36 36 } 37 }, 38 { 39 "pk": "3", 40 "model": "auth.user", 41 "fields": { 42 "username": "staff", 43 "first_name": "Staff", 44 "last_name": "Member", 45 "is_active": true, 46 "is_superuser": false, 47 "is_staff": true, 48 "last_login": "2006-12-17 07:03:31", 49 "groups": [], 50 "user_permissions": [], 51 "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 52 "email": "testclient@example.com", 53 "date_joined": "2006-12-17 07:03:31" 54 } 37 55 } 38 56 ] django/trunk/tests/regressiontests/test_client_regress/fixtures/testdata.json
r6042 r7583 17 17 "date_joined": "2006-12-17 07:03:31" 18 18 } 19 }, 20 { 21 "pk": "2", 22 "model": "auth.user", 23 "fields": { 24 "username": "inactive", 25 "first_name": "Inactive", 26 "last_name": "User", 27 "is_active": false, 28 "is_superuser": false, 29 "is_staff": false, 30 "last_login": "2006-12-17 07:03:31", 31 "groups": [], 32 "user_permissions": [], 33 "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 34 "email": "testclient@example.com", 35 "date_joined": "2006-12-17 07:03:31" 36 } 37 }, 38 { 39 "pk": "3", 40 "model": "auth.user", 41 "fields": { 42 "username": "staff", 43 "first_name": "Staff", 44 "last_name": "Member", 45 "is_active": true, 46 "is_superuser": false, 47 "is_staff": true, 48 "last_login": "2006-12-17 07:03:31", 49 "groups": [], 50 "user_permissions": [], 51 "password": "sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161", 52 "email": "testclient@example.com", 53 "date_joined": "2006-12-17 07:03:31" 54 } 19 55 } 20 56 ] django/trunk/tests/regressiontests/test_client_regress/models.py
r7578 r7583 5 5 from django.test import Client, TestCase 6 6 from django.core.urlresolvers import reverse 7 from django.core.exceptions import SuspiciousOperation 7 8 import os 8 9 … … 295 296 self.assertEqual(response.content, 'Hi, Arthur') 296 297 297 298 class ExceptionTests(TestCase): 299 fixtures = ['testdata.json'] 300 301 def test_exception_cleared(self): 302 "#5836 - A stale user exception isn't re-raised by the test client." 303 304 login = self.client.login(username='testclient',password='password') 305 self.failUnless(login, 'Could not log in') 306 try: 307 response = self.client.get("/test_client_regress/staff_only/") 308 self.fail("General users should not be able to visit this page") 309 except SuspiciousOperation: 310 pass 311 312 # At this point, an exception has been raised, and should be cleared. 313 314 # This next operation should be successful; if it isn't we have a problem. 315 login = self.client.login(username='staff', password='password') 316 self.failUnless(login, 'Could not log in') 317 try: 318 self.client.get("/test_client_regress/staff_only/") 319 except SuspiciousOperation: 320 self.fail("Staff should be able to visit this page") django/trunk/tests/regressiontests/test_client_regress/urls.py
r7330 r7583 5 5 (r'^no_template_view/$', views.no_template_view), 6 6 (r'^file_upload/$', views.file_upload_view), 7 (r'^staff_only/$', views.staff_only_view), 7 8 (r'^get_view/$', views.get_view), 8 9 url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), django/trunk/tests/regressiontests/test_client_regress/views.py
r7577 r7583 3 3 from django.contrib.auth.decorators import login_required 4 4 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError 5 from django.core.exceptions import SuspiciousOperation 5 6 6 7 def no_template_view(request): … … 24 25 return HttpResponseServerError() 25 26 27 def staff_only_view(request): 28 "A view that can only be visited by staff. Non staff members get an exception" 29 if request.user.is_staff: 30 return HttpResponse('') 31 else: 32 raise SuspiciousOperation() 33 26 34 def get_view(request): 27 35 "A simple login protected view"
