diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-11 00:23:31 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2007-02-11 00:23:31 +0000 |
| commit | f9cdde0cb41851e9d1eb70bd108debb75f267585 (patch) | |
| tree | b8f45306df30bccc5e10d1e8fd6f052764b201b7 /tests | |
| parent | 23272de5dbc9429180e309883ffd021026bd4921 (diff) | |
Fixed #3162 -- Added coded to catch and rethrow exceptions that are thrown by the views visited by the test client. Thanks, Ben <afternoon@uk2.net>.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4482 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/test_client/models.py | 12 | ||||
| -rw-r--r-- | tests/modeltests/test_client/urls.py | 3 | ||||
| -rw-r--r-- | tests/modeltests/test_client/views.py | 6 |
3 files changed, 17 insertions, 4 deletions
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index b6c3fbd5b1..74f5e9700c 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -114,4 +114,14 @@ class ClientTest(unittest.TestCase): # Check that the session was modified self.assertEquals(self.client.session['tobacconist'], 'hovercraft') -
\ No newline at end of file + + def test_view_with_exception(self): + "Request a page that is known to throw an error" + self.assertRaises(KeyError, self.client.get, "/test_client/broken_view/") + + #Try the same assertion, a different way + try: + self.client.get('/test_client/broken_view/') + self.fail('Should raise an error') + except KeyError: + pass diff --git a/tests/modeltests/test_client/urls.py b/tests/modeltests/test_client/urls.py index 5c77260c92..96da4ec34e 100644 --- a/tests/modeltests/test_client/urls.py +++ b/tests/modeltests/test_client/urls.py @@ -6,5 +6,6 @@ urlpatterns = patterns('', (r'^post_view/$', views.post_view), (r'^redirect_view/$', views.redirect_view), (r'^login_protected_view/$', views.login_protected_view), - (r'^session_view/$', views.session_view) + (r'^session_view/$', views.session_view), + (r'^broken_view/$', views.broken_view) ) diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py index 406a814dec..b1f2739845 100644 --- a/tests/modeltests/test_client/views.py +++ b/tests/modeltests/test_client/views.py @@ -36,11 +36,13 @@ login_protected_view = login_required(login_protected_view) def session_view(request): "A view that modifies the session" - request.session['tobacconist'] = 'hovercraft' t = Template('This is a view that modifies the session.', name='Session Modifying View Template') c = Context() return HttpResponse(t.render(c)) -
\ No newline at end of file + +def broken_view(request): + """A view which just raises an exception, simulating a broken view.""" + raise KeyError("Oops! Looks like you wrote some bad code.") |
