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 /tests/test_client | |
| parent | f94ce0d21de484a5783a3dcb122dc51757ed225b (diff) | |
Fixed #27184 -- Allowed uploading TemporaryFile with the test client.
Thanks Federico Capoano for finishing the patch.
Diffstat (limited to 'tests/test_client')
| -rw-r--r-- | tests/test_client/tests.py | 7 | ||||
| -rw-r--r-- | tests/test_client/urls.py | 1 | ||||
| -rw-r--r-- | tests/test_client/views.py | 5 |
3 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py index d017fa42b1..7e5795b022 100644 --- a/tests/test_client/tests.py +++ b/tests/test_client/tests.py @@ -22,6 +22,8 @@ rather than the HTML rendered to the end-user. """ from __future__ import unicode_literals +import tempfile + from django.contrib.auth.models import User from django.core import mail from django.http import HttpResponse @@ -714,6 +716,11 @@ class ClientTest(TestCase): with self.assertRaisesMessage(Exception, 'exception message'): self.client.get('/nesting_exception_view/') + def test_uploading_temp_file(self): + test_file = tempfile.TemporaryFile() + response = self.client.post('/upload_view/', data={'temp_file': test_file}) + self.assertEqual(response.content, b'temp_file') + @override_settings( MIDDLEWARE=['django.middleware.csrf.CsrfViewMiddleware'], diff --git a/tests/test_client/urls.py b/tests/test_client/urls.py index ca8d5a8fc2..9f8d09218e 100644 --- a/tests/test_client/urls.py +++ b/tests/test_client/urls.py @@ -5,6 +5,7 @@ from django.views.generic import RedirectView from . import views urlpatterns = [ + url(r'^upload_view/$', views.upload_view, name='upload_view'), url(r'^get_view/$', views.get_view, name='get_view'), url(r'^post_view/$', views.post_view), url(r'^trace_view/$', views.trace_view), diff --git a/tests/test_client/views.py b/tests/test_client/views.py index 2761f19e80..6e7d3a37d5 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -324,3 +324,8 @@ def nesting_exception_view(request): def django_project_redirect(request): return HttpResponseRedirect('https://www.djangoproject.com/') + + +def upload_view(request): + """Prints keys of request.FILES to the response.""" + return HttpResponse(', '.join(request.FILES.keys())) |
