diff options
| author | Tom Scrace <tom@scrace.org> | 2016-09-11 10:23:35 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-11-09 05:33:22 -0500 |
| commit | 5549e89b847beb89e8c8b85b6fd6924028d991c3 (patch) | |
| tree | 6811641fe1d747095dc4d6a4e6268084abb33fd4 /django/test | |
| parent | f94ce0d21de484a5783a3dcb122dc51757ed225b (diff) | |
Fixed #27184 -- Allowed uploading TemporaryFile with the test client.
Thanks Federico Capoano for finishing the patch.
Diffstat (limited to 'django/test')
| -rw-r--r-- | django/test/client.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/django/test/client.py b/django/test/client.py index aea051ed2b..be5b6198bf 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -226,7 +226,12 @@ def encode_multipart(boundary, data): def encode_file(boundary, key, file): def to_bytes(s): return force_bytes(s, settings.DEFAULT_CHARSET) - filename = os.path.basename(file.name) if hasattr(file, 'name') else '' + + # file.name might not be a string. For example, it's an int for + # tempfile.TemporaryFile(). + file_has_string_name = hasattr(file, 'name') and isinstance(file.name, six.string_types) + filename = os.path.basename(file.name) if file_has_string_name else '' + if hasattr(file, 'content_type'): content_type = file.content_type elif filename: |
