diff options
| author | Thomas Tanner <tanner@gmx.net> | 2014-11-29 17:41:06 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-12-04 07:42:03 -0500 |
| commit | 018d110ef547acb71b0526d0ff934e1e476244e4 (patch) | |
| tree | f8abd2126879aa8f9f543be5be7847027e1c549e /tests | |
| parent | dc2d75f4d43ca735bfdded52ff90458ebecb9348 (diff) | |
Fixed #23911 -- Added support for buffer file uploads in the test client
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/file_uploads/tests.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index 85363744d8..37954a99ca 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -17,7 +17,7 @@ from django.test import TestCase, client from django.test import override_settings from django.utils.encoding import force_bytes from django.utils.http import urlquote -from django.utils.six import StringIO +from django.utils.six import BytesIO, StringIO from . import uploadhandler from .models import FileModel @@ -262,6 +262,34 @@ class FileUploadTests(TestCase): self.assertLess(len(got), 256, "Got a long file name (%s characters)." % len(got)) + def test_file_content(self): + tdir = tempfile.gettempdir() + + file = tempfile.NamedTemporaryFile + with file(suffix=".ctype_extra", dir=tdir) as no_content_type, \ + file(suffix=".ctype_extra", dir=tdir) as simple_file: + no_content_type.write(b'no content') + no_content_type.seek(0) + + simple_file.write(b'text content') + simple_file.seek(0) + simple_file.content_type = 'text/plain' + + string_io = StringIO('string content') + bytes_io = BytesIO(b'binary content') + + response = self.client.post('/echo_content/', { + 'no_content_type': no_content_type, + 'simple_file': simple_file, + 'string': string_io, + 'binary': bytes_io, + }) + received = json.loads(response.content.decode('utf-8')) + self.assertEqual(received['no_content_type'], 'no content') + self.assertEqual(received['simple_file'], 'text content') + self.assertEqual(received['string'], 'string content') + self.assertEqual(received['binary'], 'binary content') + def test_content_type_extra(self): """Uploaded files may have content type parameters available.""" tdir = tempfile.gettempdir() |
