summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-12-17 08:05:51 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-12-17 08:05:51 +0000
commit03f1eb23e5c39e130744f885d480b2aa70d93088 (patch)
treed58226413fb401969b1cc49128bcab2ce72229b5 /tests/regressiontests
parent1fcb4e4bcdb99b44561b7b70c1563e059daadbd2 (diff)
Fixed #5956 -- Added a better error description for non-ASCII HTTP headers. Patch from jvloothuis.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6927 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/httpwrappers/tests.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 5cfae029bb..8fa5cdc9f3 100644
--- a/tests/regressiontests/httpwrappers/tests.py
+++ b/tests/regressiontests/httpwrappers/tests.py
@@ -391,9 +391,43 @@ u'\ufffd'
>>> q.getlist('foo')
[u'bar', u'\ufffd']
+
+######################################
+# HttpResponse with Unicode headers #
+######################################
+
+>>> r = HttpResponse()
+
+If we insert a unicode value it will be converted to an ascii
+string. This makes sure we comply with the HTTP specifications.
+
+>>> r['value'] = u'test value'
+>>> isinstance(r['value'], str)
+True
+
+An error is raised When a unicode object with non-ascii is assigned.
+
+>>> r['value'] = u't\xebst value' # doctest:+ELLIPSIS
+Traceback (most recent call last):
+...
+UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
+
+The response also converts unicode keys to strings.
+
+>>> r[u'test'] = 'testing key'
+>>> list(sorted(r.items()))[1]
+('test', 'testing key')
+
+It will also raise errors for keys with non-ascii data.
+
+>>> r[u't\xebst'] = 'testing key' # doctest:+ELLIPSIS
+Traceback (most recent call last):
+...
+UnicodeEncodeError: ..., HTTP response headers must be in US-ASCII format
+
"""
-from django.http import QueryDict
+from django.http import QueryDict, HttpResponse
if __name__ == "__main__":
import doctest