summaryrefslogtreecommitdiff
path: root/tests/regressiontests/test_client_regress/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/regressiontests/test_client_regress/models.py')
-rw-r--r--tests/regressiontests/test_client_regress/models.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index 6da7ae4445..cb8e1b3103 100644
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -11,6 +11,7 @@ from django.core.urlresolvers import reverse
from django.core.exceptions import SuspiciousOperation
from django.template import TemplateDoesNotExist, TemplateSyntaxError, Context
from django.template import loader
+from django.test.client import encode_file
class AssertContainsTests(TestCase):
def setUp(self):
@@ -34,20 +35,20 @@ class AssertContainsTests(TestCase):
try:
self.assertContains(response, 'text', status_code=999)
except AssertionError, e:
- self.assertEquals(str(e), "Couldn't retrieve page: Response code was 200 (expected 999)")
+ self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)")
try:
self.assertContains(response, 'text', status_code=999, msg_prefix='abc')
except AssertionError, e:
- self.assertEquals(str(e), "abc: Couldn't retrieve page: Response code was 200 (expected 999)")
+ self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)")
try:
self.assertNotContains(response, 'text', status_code=999)
except AssertionError, e:
- self.assertEquals(str(e), "Couldn't retrieve page: Response code was 200 (expected 999)")
+ self.assertEquals(str(e), "Couldn't retrieve content: Response code was 200 (expected 999)")
try:
self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc')
except AssertionError, e:
- self.assertEquals(str(e), "abc: Couldn't retrieve page: Response code was 200 (expected 999)")
+ self.assertEquals(str(e), "abc: Couldn't retrieve content: Response code was 200 (expected 999)")
try:
self.assertNotContains(response, 'once')
@@ -619,6 +620,7 @@ class ContextTests(TestCase):
"Context variables can be retrieved from a single context"
response = self.client.get("/test_client_regress/request_data/", data={'foo':'whiz'})
self.assertEqual(response.context.__class__, Context)
+ self.assertTrue('get-foo' in response.context)
self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'sausage')
@@ -634,6 +636,7 @@ class ContextTests(TestCase):
response = self.client.get("/test_client_regress/request_data_extended/", data={'foo':'whiz'})
self.assertEqual(response.context.__class__, ContextList)
self.assertEqual(len(response.context), 2)
+ self.assertTrue('get-foo' in response.context)
self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz')
self.assertEqual(response.context['data'], 'bacon')
@@ -821,3 +824,26 @@ class UnicodePayloadTests(TestCase):
response = self.client.post("/test_client_regress/parse_unicode_json/", json,
content_type="application/json; charset=koi8-r")
self.assertEqual(response.content, json.encode('koi8-r'))
+
+class DummyFile(object):
+ def __init__(self, filename):
+ self.name = filename
+ def read(self):
+ return 'TEST_FILE_CONTENT'
+
+class UploadedFileEncodingTest(TestCase):
+ def test_file_encoding(self):
+ encoded_file = encode_file('TEST_BOUNDARY', 'TEST_KEY', DummyFile('test_name.bin'))
+ self.assertEqual('--TEST_BOUNDARY', encoded_file[0])
+ self.assertEqual('Content-Disposition: form-data; name="TEST_KEY"; filename="test_name.bin"', encoded_file[1])
+ self.assertEqual('TEST_FILE_CONTENT', encoded_file[-1])
+
+ def test_guesses_content_type_on_file_encoding(self):
+ self.assertEqual('Content-Type: application/octet-stream',
+ encode_file('IGNORE', 'IGNORE', DummyFile("file.bin"))[2])
+ self.assertEqual('Content-Type: text/plain',
+ encode_file('IGNORE', 'IGNORE', DummyFile("file.txt"))[2])
+ self.assertEqual('Content-Type: application/zip',
+ encode_file('IGNORE', 'IGNORE', DummyFile("file.zip"))[2])
+ self.assertEqual('Content-Type: application/octet-stream',
+ encode_file('IGNORE', 'IGNORE', DummyFile("file.unknown"))[2])