Ticket #6009: patch-6009-1.diff

File patch-6009-1.diff, 3.0 KB (added by Leah Culver, 16 years ago)

added tests for unicode filenames in forms and model field

  • tests/regressiontests/forms/models.py

     
     1# -*- coding: utf-8 -*-
    12import datetime
    23
    34from django.db import models
     5from django import newforms as django_forms
    46
    57class BoundaryModel(models.Model):
    68    positive_integer = models.PositiveIntegerField(null=True, blank=True)
     
    1416    """For ModelChoiceField and ModelMultipleChoiceField tests."""
    1517    name = models.CharField(max_length=10)
    1618
     19class FileModel(models.Model):
     20    file = models.FileField(upload_to='/')
     21
     22class FileForm(django_forms.Form):
     23    file1 = django_forms.FileField()
     24
    1725__test__ = {'API_TESTS': """
     26
     27>>> from django.core.files.uploadedfile import SimpleUploadedFile
    1828>>> from django.newforms import form_for_model, form_for_instance
    1929
     30# FileModel with unicode filename and data #########################
     31>>> f = FileForm(data={}, files={'file1': SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')}, auto_id=False)
     32>>> f.is_valid()
     33True
     34>>> f.cleaned_data
     35{'file1': <SimpleUploadedFile: 我隻氣墊船裝滿晒鱔.txt (text/plain)>}
     36>>> m = FileModel.objects.create(file=f.cleaned_data['file1'])
     37
    2038# Boundary conditions on a PostitiveIntegerField #########################
    2139>>> BoundaryForm = form_for_model(BoundaryModel)
    2240>>> f = BoundaryForm({'positive_integer':100})
  • tests/regressiontests/forms/fields.py

     
    802802>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content')))
    803803<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
    804804
     805>>> type(f.clean(SimpleUploadedFile('我隻氣墊船裝滿晒鱔.txt', 'मेरी मँडराने वाली नाव सर्पमीनों से भरी ह')))
     806<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
     807
    805808>>> type(f.clean(SimpleUploadedFile('name', 'Some File Content'), 'files/test4.pdf'))
    806809<class 'django.core.files.uploadedfile.SimpleUploadedFile'>
    807810
  • tests/regressiontests/forms/forms.py

     
    14801480>>> f.is_valid()
    14811481True
    14821482
     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
    14831487# Basic form processing in a view #############################################
    14841488
    14851489>>> from django.template import Template, Context
Back to Top