Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #6009 -- Added regression tests to show that uploading non-ASCII

filenames now works properly. Patch from Leah Culver.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@7987 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 344383284cf1a51fa646bc8926014f78ba512a56 1 parent a103786
Malcolm Tredinnick authored July 19, 2008
3  tests/regressiontests/forms/fields.py
@@ -802,6 +802,9 @@
802 802
 >>> type(f.clean(SimpleUploadedFile('name', 'Some File Content')))
803 803
 <class 'django.core.files.uploadedfile.SimpleUploadedFile'>
804 804
 
  805
+>>> type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')))
  806
+<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
  807
+
805 808
 >>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf'))
806 809
 <class 'django.core.files.uploadedfile.SimpleUploadedFile'>
807 810
 
4  tests/regressiontests/forms/forms.py
@@ -1480,6 +1480,10 @@
1480 1480
 >>> f.is_valid()
1481 1481
 True
1482 1482
 
  1483
+>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')}, auto_id=False)
  1484
+>>> print f
  1485
+<tr><th>File1:</th><td><input type="file" name="file1" /></td></tr>
  1486
+
1483 1487
 # Basic form processing in a view #############################################
1484 1488
 
1485 1489
 >>> from django.template import Template, Context
19  tests/regressiontests/forms/models.py
... ...
@@ -1,6 +1,10 @@
  1
+# -*- coding: utf-8 -*-
1 2
 import datetime
2 3
 
3 4
 from django.db import models
  5
+# Can't import as "forms" due to implementation details in the test suite (the
  6
+# current file is called "forms" an is already imported).
  7
+from django import forms as django_forms
4 8
 
5 9
 class BoundaryModel(models.Model):
6 10
     positive_integer = models.PositiveIntegerField(null=True, blank=True)
@@ -14,8 +18,23 @@ class ChoiceModel(models.Model):
14 18
     """For ModelChoiceField and ModelMultipleChoiceField tests."""
15 19
     name = models.CharField(max_length=10)
16 20
 
  21
+class FileModel(models.Model):
  22
+    file = models.FileField(upload_to='/')
  23
+
  24
+class FileForm(django_forms.Form):
  25
+    file1 = django_forms.FileField()
  26
+
17 27
 __test__ = {'API_TESTS': """
18 28
 >>> from django.forms import form_for_model, form_for_instance
  29
+>>> from django.core.files.uploadedfile import SimpleUploadedFile
  30
+
  31
+# FileModel with unicode filename and data #########################
  32
+>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')}, auto_id=False)
  33
+>>> f.is_valid()
  34
+True
  35
+>>> f.cleaned_data
  36
+{'file1': <SimpleUploadedFile: 我隻氣墊船裝滿晒鱔.txt (text/plain)>}
  37
+>>> m = FileModel.objects.create(file=f.cleaned_data['file1'])
19 38
 
20 39
 # Boundary conditions on a PostitiveIntegerField #########################
21 40
 >>> BoundaryForm = form_for_model(BoundaryModel)

0 notes on commit 3443832

Please sign in to comment.
Something went wrong with that request. Please try again.