diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-11 20:02:08 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-06-11 20:02:08 +0000 |
| commit | d3980231ff8cc04d1f17e3d440606b111230b36d (patch) | |
| tree | 8a9d2f2f8aa62343886ad3be32603079a2f2a93f /tests/regressiontests | |
| parent | 748ea65a6180293c356faa3ff0e754cb1d678d14 (diff) | |
unicode: Changed the way re-encoding of form field submission works so that
file uploads are no longer completely broken. Added tests for this as well.
git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5464 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/httpwrappers/tests.py | 14 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/models.py | 10 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/urls.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/test_client_regress/views.py | 14 |
4 files changed, 31 insertions, 9 deletions
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index ca42752a9f..9d5ca2006a 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -16,7 +16,7 @@ Traceback (most recent call last): AttributeError: This QueryDict instance is immutable >>> q.get('foo', 'default') -u'default' +'default' >>> q.getlist('foo') [] @@ -103,7 +103,7 @@ False >>> q['name'] = 'john' >>> q.get('foo', 'default') -u'default' +'default' >>> q.get('name', 'default') u'john' @@ -167,10 +167,10 @@ u'hello' [u'bar', u'baz', u'another', u'hello'] >>> q.pop('foo', 'not there') -u'not there' +'not there' >>> q.get('foo', 'not there') -u'not there' +'not there' >>> q.setdefault('foo', 'bar') u'bar' @@ -201,7 +201,7 @@ u'bar' >>> q['bar'] Traceback (most recent call last): ... -MultiValueDictKeyError: "Key 'bar' not found in <MultiValueDict: {'foo': ['bar']}>" +MultiValueDictKeyError: "Key 'bar' not found in <MultiValueDict: {u'foo': [u'bar']}>" >>> q['something'] = 'bar' Traceback (most recent call last): @@ -212,7 +212,7 @@ AttributeError: This QueryDict instance is immutable u'bar' >>> q.get('bar', 'default') -u'default' +'default' >>> q.getlist('foo') [u'bar'] @@ -303,7 +303,7 @@ AttributeError: This QueryDict instance is immutable u'no' >>> q.get('foo', 'default') -u'default' +'default' >>> q.getlist('vote') [u'yes', u'no'] diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 096682ad39..35aaaf9720 100644 --- a/tests/regressiontests/test_client_regress/models.py +++ b/tests/regressiontests/test_client_regress/models.py @@ -4,6 +4,7 @@ Regression tests for the Test Client, especially the customized assertions. """ from django.test import Client, TestCase from django.core import mail +import os class AssertTemplateUsedTests(TestCase): fixtures = ['testdata.json'] @@ -162,3 +163,12 @@ class AssertFormErrorTests(TestCase): except AssertionError, e: self.assertEqual(str(e), "The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])") +class AssertFileUploadTests(TestCase): + def test_simple_upload(self): + fd = open(os.path.join(os.path.dirname(__file__), "views.py")) + post_data = { + 'name': 'Ringo', + 'file_field': fd, + } + response = self.client.post('/test_client_regress/file_upload/', post_data) + self.assertEqual(response.status_code, 200) diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py index e9cd0aea15..160f9f992d 100644 --- a/tests/regressiontests/test_client_regress/urls.py +++ b/tests/regressiontests/test_client_regress/urls.py @@ -1,7 +1,7 @@ from django.conf.urls.defaults import * -from django.views.generic.simple import redirect_to import views urlpatterns = patterns('', (r'^no_template_view/$', views.no_template_view), + (r'^file_upload/$', views.file_upload_view), ) diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py index d8dd2b349c..8728ab0d7d 100644 --- a/tests/regressiontests/test_client_regress/views.py +++ b/tests/regressiontests/test_client_regress/views.py @@ -1,8 +1,20 @@ from django.core.mail import EmailMessage, SMTPConnection -from django.http import HttpResponse +from django.http import HttpResponse, HttpResponseServerError from django.shortcuts import render_to_response def no_template_view(request): "A simple view that expects a GET request, and returns a rendered template" return HttpResponse("No template used") +def file_upload_view(request): + """ + Check that a file upload can be updated into the POST dictionary without + going pear-shaped. + """ + form_data = request.POST.copy() + form_data.update(request.FILES) + if isinstance(form_data['file_field'], dict) and isinstance(form_data['name'], unicode): + return HttpResponse('') + else: + return HttpResponseServerError() + |
