﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23912	django.test.client.RequestFactory file upload fails	Kévin Etienne	nobody	"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
}}}"	Bug	closed	Testing framework	dev	Normal	duplicate			Accepted	1	0	0	0	0	0
