diff options
| author | Carl Meyer <carl@oddbird.net> | 2012-02-10 22:51:07 +0000 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2012-02-10 22:51:07 +0000 |
| commit | 0ce6636102d9e1c8c158c0e3eadb5a5db6b06a71 (patch) | |
| tree | a1813d4a1215b47823c7c6b085be69ad6e9a4b2b /tests/regressiontests/requests/tests.py | |
| parent | 8be356ea99489e932174f7c1d54d2ff766a52311 (diff) | |
Fixed #17277 - Wrap IOErrors raised due to client disconnect in a specific IOError subclass so they can be distinguished from more serious errors. Thanks David Lowe.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17493 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/requests/tests.py')
| -rw-r--r-- | tests/regressiontests/requests/tests.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index e71c6f6eaa..d4239448dd 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import time import warnings from datetime import datetime, timedelta @@ -6,7 +8,7 @@ from StringIO import StringIO from django.conf import settings from django.core.handlers.modpython import ModPythonRequest from django.core.handlers.wsgi import WSGIRequest, LimitedStream -from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr +from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_repr, UnreadablePostError from django.test.utils import get_warnings_state, restore_warnings_state from django.utils import unittest from django.utils.http import cookie_date @@ -430,3 +432,21 @@ class RequestsTests(unittest.TestCase): self.assertEqual(request.body, request.raw_post_data) finally: restore_warnings_state(warnings_state) + + + def test_POST_connection_error(self): + """ + If wsgi.input.read() raises an exception while trying to read() the + POST, the exception should be identifiable (not a generic IOError). + """ + class ExplodingStringIO(StringIO): + def read(self, len=0): + raise IOError("kaboom!") + + payload = 'name=value' + request = WSGIRequest({'REQUEST_METHOD': 'POST', + 'CONTENT_LENGTH': len(payload), + 'wsgi.input': ExplodingStringIO(payload)}) + + with self.assertRaises(UnreadablePostError): + request.raw_post_data |
