From 953badbea5a04159adbfa970f5805c0232b6a401 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Wed, 4 Jul 2007 12:11:04 +0000 Subject: Merged Unicode branch into trunk (r4952:5608). This should be fully backwards compatible for all practical purposes. Fixed #2391, #2489, #2996, #3322, #3344, #3370, #3406, #3432, #3454, #3492, #3582, #3690, #3878, #3891, #3937, #4039, #4141, #4227, #4286, #4291, #4300, #4452, #4702 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5609 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor.py | 14 ++++----- tests/regressiontests/forms/regressions.py | 49 +++++++++++++++++++++++++++--- tests/regressiontests/forms/tests.py | 2 +- 3 files changed, 52 insertions(+), 13 deletions(-) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/localflavor.py b/tests/regressiontests/forms/localflavor.py index ede89de2a0..252aa10b34 100644 --- a/tests/regressiontests/forms/localflavor.py +++ b/tests/regressiontests/forms/localflavor.py @@ -1303,9 +1303,9 @@ strict. >>> rut = CLRutField() >>> rut.clean('11-6') -'11-6' +u'11-6' >>> rut.clean('116') -'11-6' +u'11-6' # valid format, bad verifier. >>> rut.clean('11.111.111-0') @@ -1318,13 +1318,13 @@ Traceback (most recent call last): ValidationError: [u'The Chilean RUT is not valid.'] >>> rut.clean('767484100') -'76.748.410-0' +u'76.748.410-0' >>> rut.clean('78.412.790-7') -'78.412.790-7' +u'78.412.790-7' >>> rut.clean('8.334.6043') -'8.334.604-3' +u'8.334.604-3' >>> rut.clean('76793310-K') -'76.793.310-K' +u'76.793.310-K' Strict RUT usage (does not allow imposible values) >>> rut = CLRutField(strict=True) @@ -1346,7 +1346,7 @@ Traceback (most recent call last): ... ValidationError: [u'Enter valid a Chilean RUT. The format is XX.XXX.XXX-X.'] >>> rut.clean('78.412.790-7') -'78.412.790-7' +u'78.412.790-7' >>> rut.clean('8.334.6043') Traceback (most recent call last): ... diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py index 5fe057b5d8..784ef49902 100644 --- a/tests/regressiontests/forms/regressions.py +++ b/tests/regressiontests/forms/regressions.py @@ -16,24 +16,63 @@ u'

F1:

\n

####################### There were some problems with form translations in #3600 ->>> from django.utils.translation import gettext_lazy, activate, deactivate +>>> from django.utils.translation import ugettext_lazy, activate, deactivate >>> class SomeForm(Form): -... username = CharField(max_length=10, label=gettext_lazy('Username')) +... username = CharField(max_length=10, label=ugettext_lazy('Username')) >>> f = SomeForm() >>> print f.as_p()

+ +Translations are done at rendering time, so multi-lingual apps can define forms +early and still send back the right translation. + +# XFAIL >>> activate('de') >>> print f.as_p()

+>>> activate('pl') +>>> f.as_p() +u'

' >>> deactivate() Unicode decoding problems... ->>> GENDERS = (('0', u'En tied\xe4'), ('1', u'Mies'), ('2', u'Nainen')) +>>> GENDERS = ((u'\xc5', u'En tied\xe4'), (u'\xf8', u'Mies'), (u'\xdf', u'Nainen')) >>> class SomeForm(Form): -... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect()) +... somechoice = ChoiceField(choices=GENDERS, widget=RadioSelect(), label=u'\xc5\xf8\xdf') >>> f = SomeForm() >>> f.as_p() -u'

' +u'

' + +Testing choice validation with UTF-8 bytestrings as input (these are the +Russian abbreviations "мес." and "шт.". + +>>> UNITS = (('\xd0\xbc\xd0\xb5\xd1\x81.', '\xd0\xbc\xd0\xb5\xd1\x81.'), ('\xd1\x88\xd1\x82.', '\xd1\x88\xd1\x82.')) +>>> f = ChoiceField(choices=UNITS) +>>> f.clean(u'\u0448\u0442.') +u'\u0448\u0442.' +>>> f.clean('\xd1\x88\xd1\x82.') +u'\u0448\u0442.' + +Translated error messages used to be buggy. +>>> activate('ru') +>>> f = SomeForm({}) +>>> f.as_p() +u'\n

' +>>> deactivate() + +####################### +# Miscellaneous Tests # +####################### + +There once was a problem with Form fields called "data". Let's make sure that +doesn't come back. +>>> class DataForm(Form): +... data = CharField(max_length=10) +>>> f = DataForm({'data': 'xyzzy'}) +>>> f.is_valid() +True +>>> f.cleaned_data +{'data': u'xyzzy'} ####################### # Miscellaneous Tests # diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 0808ebe97e..67d527a08e 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -3374,7 +3374,7 @@ does not have help text, nothing will be output. >>> Template('{{ form.password1.help_text }}').render(Context({'form': UserRegistration(auto_id=False)})) -'' +u'' The label_tag() method takes an optional attrs argument: a dictionary of HTML attributes to add to the