From 8ceeb6d8cb5933ae518b2c75338decd2fc1bc97b Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Mon, 9 Apr 2007 23:39:40 +0000 Subject: boulder-oracle-sprint: Merged to [4989] git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4990 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor.py | 152 ++++++++++++++++++++++++++--- tests/regressiontests/forms/tests.py | 26 ++--- 2 files changed, 154 insertions(+), 24 deletions(-) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/localflavor.py b/tests/regressiontests/forms/localflavor.py index e9c027b5c8..b37aa3c6ea 100644 --- a/tests/regressiontests/forms/localflavor.py +++ b/tests/regressiontests/forms/localflavor.py @@ -6,7 +6,7 @@ localflavor_tests = r""" USZipCodeField validates that the data is either a five-digit U.S. zip code or a zip+4. ->>> from django.contrib.localflavor.usa.forms import USZipCodeField +>>> from django.contrib.localflavor.us.forms import USZipCodeField >>> f = USZipCodeField() >>> f.clean('60606') u'60606' @@ -67,7 +67,7 @@ u'' USPhoneNumberField validates that the data is a valid U.S. phone number, including the area code. It's normalized to XXX-XXX-XXXX format. ->>> from django.contrib.localflavor.usa.forms import USPhoneNumberField +>>> from django.contrib.localflavor.us.forms import USPhoneNumberField >>> f = USPhoneNumberField() >>> f.clean('312-555-1212') u'312-555-1212' @@ -136,7 +136,7 @@ u'' USStateField validates that the data is either an abbreviation or name of a U.S. state. ->>> from django.contrib.localflavor.usa.forms import USStateField +>>> from django.contrib.localflavor.us.forms import USStateField >>> f = USStateField() >>> f.clean('il') u'IL' @@ -181,7 +181,7 @@ u'' USStateSelect is a Select widget that uses a list of U.S. states/territories as its choices. ->>> from django.contrib.localflavor.usa.forms import USStateSelect +>>> from django.contrib.localflavor.us.forms import USStateSelect >>> w = USStateSelect() >>> print w.render('state', 'IL') # USSocialSecurityNumberField ################################################# ->>> from django.contrib.localflavor.usa.forms import USSocialSecurityNumberField +>>> from django.contrib.localflavor.us.forms import USSocialSecurityNumberField >>> f = USSocialSecurityNumberField() >>> f.clean('987-65-4330') u'987-65-4330' @@ -406,7 +406,7 @@ u'' # FRDepartmentSelect ############################################################### -FRDepartmentSelect is a Select widget that uses a list of french departments +FRDepartmentSelect is a Select widget that uses a list of french departments including DOM TOM >>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect >>> w = FRDepartmentSelect() @@ -686,11 +686,11 @@ u'' >>> f.clean('') u'' -# FIMunicipalitySelect ############################################################### +# FIMunicipalitySelect ############################################################### -A Select widget that uses a list of Finnish municipalities as its choices. ->>> from django.contrib.localflavor.fi.forms import FIMunicipalitySelect ->>> w = FIMunicipalitySelect() +A Select widget that uses a list of Finnish municipalities as its choices. +>>> from django.contrib.localflavor.fi.forms import FIMunicipalitySelect +>>> w = FIMunicipalitySelect() >>> unicode(w.render('municipalities', 'turku')) u'' @@ -881,5 +881,135 @@ u'9786324830D-6104243-0910271-2' >>> f.clean('0434657485D-6407276-0508137-9') Traceback (most recent call last): ... -ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format'] +ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'] + +## AUPostCodeField ########################################################## + +A field that accepts a four digit Australian post code. + +>>> from django.contrib.localflavor.au.forms import AUPostCodeField +>>> f = AUPostCodeField() +>>> f.clean('1234') +u'1234' +>>> f.clean('2000') +u'2000' +>>> f.clean('abcd') +Traceback (most recent call last): +... +ValidationError: [u'Enter a 4 digit post code.'] +>>> f.clean('20001') +Traceback (most recent call last): +... +ValidationError: [u'Enter a 4 digit post code.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +>>> f = AUPostCodeField(required=False) +>>> f.clean('1234') +u'1234' +>>> f.clean('2000') +u'2000' +>>> f.clean('abcd') +Traceback (most recent call last): +... +ValidationError: [u'Enter a 4 digit post code.'] +>>> f.clean('20001') +Traceback (most recent call last): +... +ValidationError: [u'Enter a 4 digit post code.'] +>>> f.clean(None) +u'' +>>> f.clean('') +u'' + +## AUPhoneNumberField ######################################################## + +A field that accepts a 10 digit Australian phone number. +llows spaces and parentheses around area code. + +>>> from django.contrib.localflavor.au.forms import AUPhoneNumberField +>>> f = AUPhoneNumberField() +>>> f.clean('1234567890') +u'1234567890' +>>> f.clean('0213456789') +u'0213456789' +>>> f.clean('02 13 45 67 89') +u'0213456789' +>>> f.clean('(02) 1345 6789') +u'0213456789' +>>> f.clean('(02) 1345-6789') +u'0213456789' +>>> f.clean('(02)1345-6789') +u'0213456789' +>>> f.clean('0408 123 456') +u'0408123456' +>>> f.clean('123') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must contain 10 digits.'] +>>> f.clean('1800DJANGO') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must contain 10 digits.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +>>> f = AUPhoneNumberField(required=False) +>>> f.clean('1234567890') +u'1234567890' +>>> f.clean('0213456789') +u'0213456789' +>>> f.clean('02 13 45 67 89') +u'0213456789' +>>> f.clean('(02) 1345 6789') +u'0213456789' +>>> f.clean('(02) 1345-6789') +u'0213456789' +>>> f.clean('(02)1345-6789') +u'0213456789' +>>> f.clean('0408 123 456') +u'0408123456' +>>> f.clean('123') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must contain 10 digits.'] +>>> f.clean('1800DJANGO') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must contain 10 digits.'] +>>> f.clean(None) +u'' +>>> f.clean('') +u'' + +## AUStateSelect ############################################################# + +AUStateSelect is a Select widget that uses a list of Australian +states/territories as its choices. + +>>> from django.contrib.localflavor.au.forms import AUStateSelect +>>> f = AUStateSelect() +>>> print f.render('state', 'NSW') + """ diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index e78a4d0ec3..4521d17d7f 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -193,30 +193,30 @@ u'' +u'' >>> w.render('msg', None) -u'' +u'' >>> w.render('msg', 'value') -u'' +u'' >>> w.render('msg', 'some "quoted" & ampersanded value') -u'' ->>> w.render('msg', 'value', attrs={'class': 'pretty'}) -u'' +u'' +>>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}) +u'' You can also pass 'attrs' to the constructor: >>> w = Textarea(attrs={'class': 'pretty'}) >>> w.render('msg', '') -u'' +u'' >>> w.render('msg', 'example') -u'' +u'' 'attrs' passed to render() get precedence over those passed to the constructor: >>> w = Textarea(attrs={'class': 'pretty'}) >>> w.render('msg', '', attrs={'class': 'special'}) -u'' +u'' >>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) -u'' +u'' # CheckboxInput Widget ######################################################## @@ -1966,12 +1966,12 @@ Any Field can have a Widget class passed to its constructor: >>> print f['subject'] >>> print f['message'] - + as_textarea(), as_text() and as_hidden() are shortcuts for changing the output widget type: >>> f['subject'].as_textarea() -u'' +u'' >>> f['message'].as_text() u'' >>> f['message'].as_hidden() @@ -1991,7 +1991,7 @@ as_hidden(): u'' >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False) >>> f['subject'].as_textarea() -u'' +u'' >>> f['message'].as_text() u'' >>> f['message'].as_hidden() -- cgit v1.3