From 0b7dd14d1f87e2ecef7aacc39fe4189667ed4fdf Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Fri, 9 Mar 2007 17:43:46 +0000 Subject: boulder-oracle-sprint: Merged to trunk [4692]. git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4695 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 485 ++++++++++++++++++++++++++++++++++- 1 file changed, 476 insertions(+), 9 deletions(-) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 20a1937f56..a9ce8d23b3 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -72,6 +72,22 @@ u'' >>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) u'' +The render_value argument lets you specify whether the widget should render +its value. You may want to do this for security reasons. +>>> w = PasswordInput(render_value=True) +>>> w.render('email', 'secret') +u'' +>>> w = PasswordInput(render_value=False) +>>> w.render('email', '') +u'' +>>> w.render('email', None) +u'' +>>> w.render('email', 'secret') +u'' +>>> w = PasswordInput(attrs={'class': 'fun'}, render_value=False) +>>> w.render('email', 'secret') +u'' + # HiddenInput Widget ############################################################ >>> w = HiddenInput() @@ -302,6 +318,7 @@ The value is compared to its str(): The 'choices' argument can be any iterable: +>>> from itertools import chain >>> def get_choices(): ... for i in range(5): ... yield (i, i) @@ -313,6 +330,17 @@ The 'choices' argument can be any iterable: +>>> things = ({'id': 1, 'name': 'And Boom'}, {'id': 2, 'name': 'One More Thing!'}) +>>> class SomeForm(Form): +... somechoice = ChoiceField(choices=chain((('', '-'*9),), [(thing['id'], thing['name']) for thing in things])) +>>> f = SomeForm() +>>> f.as_table() +u'' +>>> f.as_table() +u'' +>>> f = SomeForm({'somechoice': 2}) +>>> f.as_table() +u'' You can also pass 'choices' to the constructor: >>> w = Select(choices=[(1, 1), (2, 2), (3, 3)]) @@ -1493,7 +1521,7 @@ u'1' >>> f.clean('3') Traceback (most recent call last): ... -ValidationError: [u'Select a valid choice. 3 is not one of the available choices.'] +ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] >>> f = ChoiceField(choices=[('1', '1'), ('2', '2')], required=False) >>> f.clean('') @@ -1507,7 +1535,7 @@ u'1' >>> f.clean('3') Traceback (most recent call last): ... -ValidationError: [u'Select a valid choice. 3 is not one of the available choices.'] +ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] >>> f = ChoiceField(choices=[('J', 'John'), ('P', 'Paul')]) >>> f.clean('J') @@ -1515,7 +1543,7 @@ u'J' >>> f.clean('John') Traceback (most recent call last): ... -ValidationError: [u'Select a valid choice. John is not one of the available choices.'] +ValidationError: [u'Select a valid choice. That choice is not one of the available choices.'] # NullBooleanField ############################################################ @@ -1983,6 +2011,19 @@ For a form with a +A subtlety: If one of the choices' value is the empty string and the form is +unbound, then the