#23912: django.test.client.RequestFactory file upload
-----------------------------------+--------------------
Reporter: KevinEtienne | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
When using `post` on `RequestFactory` to upload a file we are calling
`django.test.client.encode_file`.
`encode_file` tries to join a list of bytes but `file.read()` return a
`str`.
See here:
https://github.com/django/django/blob/e22c64dfc0230134c0e9d9ae1d9a5c1589fc8b6e/django/test/client.py#L195-L202
Which result to the following error:
{{{#!bash
======================================================================
ERROR: test_upload_file (test_client.tests.RequestFactoryTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tests.py", line 10, in test_upload_file
factory.post('/somewhere/', {'file': f})
File "/Users/k/code/github.com/incuna/django/django/test/client.py",
line 293, in post
post_data = self._encode_data(data, content_type)
File "/Users/k/code/github.com/incuna/django/django/test/client.py",
line 257, in _encode_data
return encode_multipart(BOUNDARY, data)
File "/Users/k/code/github.com/incuna/django/django/test/client.py",
line 182, in encode_multipart
return b'\r\n'.join(lines)
TypeError: sequence item 4: expected bytes, bytearray, or an object with
the buffer interface, str found
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23912>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.e9430986365995fbf995716dee7fcd7e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.