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/modeltests/model_forms/models.py | 10 +- tests/regressiontests/fixtures_regress/__init__.py | 0 .../fixtures_regress/fixtures/sequence.json | 10 ++ tests/regressiontests/fixtures_regress/models.py | 22 +++ tests/regressiontests/forms/localflavor.py | 152 +++++++++++++++++++-- tests/regressiontests/forms/tests.py | 26 ++-- 6 files changed, 191 insertions(+), 29 deletions(-) create mode 100644 tests/regressiontests/fixtures_regress/__init__.py create mode 100644 tests/regressiontests/fixtures_regress/fixtures/sequence.json create mode 100644 tests/regressiontests/fixtures_regress/models.py (limited to 'tests') diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index d91f1d2d45..2757787571 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -159,7 +159,7 @@ represented by a ChoiceField. -Article: +Article: Categories: -
  • Article:
  • +
  • Article:
  • Categories:
  • -
  • Article:
  • +
  • Article:
  • Categories:
  • -
  • Article:
  • +
  • Article:
  • Categories:
  • -
  • Article:
  • +
  • Article:
  • Categories: @@ -247,7 +247,7 @@ as its choices. # 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