diff options
Diffstat (limited to 'django/test')
-rw-r--r-- | django/test/client.py | 6 | ||||
-rw-r--r-- | django/test/testcases.py | 8 | ||||
-rw-r--r-- | django/test/utils.py | 6 |
3 files changed, 15 insertions, 5 deletions
diff --git a/django/test/client.py b/django/test/client.py index e5a16b6e79..498af5c344 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -3,6 +3,7 @@ from urlparse import urlparse, urlunparse, urlsplit import sys import os import re +import mimetypes try: from cStringIO import StringIO except ImportError: @@ -138,11 +139,14 @@ def encode_multipart(boundary, data): def encode_file(boundary, key, file): to_str = lambda s: smart_str(s, settings.DEFAULT_CHARSET) + content_type = mimetypes.guess_type(file.name)[0] + if content_type is None: + content_type = 'application/octet-stream' return [ '--' + boundary, 'Content-Disposition: form-data; name="%s"; filename="%s"' \ % (to_str(key), to_str(os.path.basename(file.name))), - 'Content-Type: application/octet-stream', + 'Content-Type: %s' % content_type, '', file.read() ] diff --git a/django/test/testcases.py b/django/test/testcases.py index 276d1f3c41..10bd6c6c9f 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -347,7 +347,7 @@ class TransactionTestCase(unittest.TestCase): def assertContains(self, response, text, count=None, status_code=200, msg_prefix=''): """ - Asserts that a response indicates that a page was retrieved + Asserts that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected), and that ``text`` occurs ``count`` times in the content of the response. If ``count`` is None, the count doesn't matter - the assertion is true @@ -357,7 +357,7 @@ class TransactionTestCase(unittest.TestCase): msg_prefix += ": " self.assertEqual(response.status_code, status_code, - msg_prefix + "Couldn't retrieve page: Response code was %d" + msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) text = smart_str(text, response._charset) real_count = response.content.count(text) @@ -372,7 +372,7 @@ class TransactionTestCase(unittest.TestCase): def assertNotContains(self, response, text, status_code=200, msg_prefix=''): """ - Asserts that a response indicates that a page was retrieved + Asserts that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected), and that ``text`` doesn't occurs in the content of the response. """ @@ -380,7 +380,7 @@ class TransactionTestCase(unittest.TestCase): msg_prefix += ": " self.assertEqual(response.status_code, status_code, - msg_prefix + "Couldn't retrieve page: Response code was %d" + msg_prefix + "Couldn't retrieve content: Response code was %d" " (expected %d)" % (response.status_code, status_code)) text = smart_str(text, response._charset) self.assertEqual(response.content.count(text), 0, diff --git a/django/test/utils.py b/django/test/utils.py index b6ab39901b..404d130297 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -19,6 +19,12 @@ class ContextList(list): else: return super(ContextList, self).__getitem__(key) + def __contains__(self, key): + try: + value = self[key] + except KeyError: + return False + return True def instrumented_test_render(self, context): """ |