diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2010-12-18 20:30:28 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2010-12-18 20:30:28 +0000 |
| commit | eb4b1ab1a0397871bd0ab4c600b2f80ffb17a8d9 (patch) | |
| tree | 9c4cdcd9a71fc9445118c0b9da3873e8f857a852 | |
| parent | b148aead7d54a0e5e6ebfd02c7b46bb6a396a0ec (diff) | |
Converted Finnish localflavor doctests to unittests. We have always been at war with doctests. Thanks to Idan Gazit.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14938 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | tests/regressiontests/forms/localflavor/fi.py | 129 | ||||
| -rw-r--r-- | tests/regressiontests/forms/localflavortests.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests/__init__.py | 1 |
3 files changed, 36 insertions, 97 deletions
diff --git a/tests/regressiontests/forms/localflavor/fi.py b/tests/regressiontests/forms/localflavor/fi.py index cc3723e4a2..161eb1743b 100644 --- a/tests/regressiontests/forms/localflavor/fi.py +++ b/tests/regressiontests/forms/localflavor/fi.py @@ -1,58 +1,13 @@ -# -*- coding: utf-8 -*- -# Tests for the contrib/localflavor/ FI form fields. +from django.contrib.localflavor.fi.forms import (FIZipCodeField, + FISocialSecurityNumber, FIMunicipalitySelect) -tests = r""" -# FIZipCodeField ############################################################# +from utils import LocalFlavorTestCase -FIZipCodeField validates that the data is a valid FI zipcode. ->>> from django.contrib.localflavor.fi.forms import FIZipCodeField ->>> f = FIZipCodeField() ->>> f.clean('20540') -u'20540' ->>> f.clean('20101') -u'20101' ->>> f.clean('20s40') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean('205401') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> 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 = FIZipCodeField(required=False) ->>> f.clean('20540') -u'20540' ->>> f.clean('20101') -u'20101' ->>> f.clean('20s40') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean('205401') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXXX.'] ->>> f.clean(None) -u'' ->>> f.clean('') -u'' - -# 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'<select name="municipalities"> +class FILocalFlavorTests(LocalFlavorTestCase): + def test_FIMunicipalitySelect(self): + f = FIMunicipalitySelect() + out = u'''<select name="municipalities"> <option value="akaa">Akaa</option> <option value="alajarvi">Alaj\xe4rvi</option> <option value="alavieska">Alavieska</option> @@ -395,49 +350,33 @@ u'<select name="municipalities"> <option value="ypaja">Yp\xe4j\xe4</option> <option value="ahtari">\xc4ht\xe4ri</option> <option value="aanekoski">\xc4\xe4nekoski</option> -</select>' - +</select>''' + self.assertEquals(f.render('municipalities', 'turku'), out) -# FISocialSecurityNumber ############################################################## + def test_FIZipCodeField(self): + error_format = [u'Enter a zip code in the format XXXXX.'] + valid = { + '20540': '20540', + '20101': '20101', + } + invalid = { + '20s40': error_format, + '205401': error_format + } + self.assertFieldOutput(FIZipCodeField, valid, invalid) ->>> from django.contrib.localflavor.fi.forms import FISocialSecurityNumber ->>> f = FISocialSecurityNumber() ->>> f.clean('010101-0101') -u'010101-0101' ->>> f.clean('010101+0101') -u'010101+0101' ->>> f.clean('010101A0101') -u'010101A0101' ->>> f.clean('101010-0102') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Finnish social security number.'] ->>> f.clean('10a010-0101') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Finnish social security number.'] ->>> f.clean('101010-0\xe401') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Finnish social security number.'] ->>> f.clean('101010b0101') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Finnish social security number.'] ->>> f.clean('') -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] + def test_FISocialSecurityNumber(self): + error_invalid = [u'Enter a valid Finnish social security number.'] + valid = { + '010101-0101': '010101-0101', + '010101+0101': '010101+0101', + '010101A0101': '010101A0101', + } + invalid = { + '101010-0102': error_invalid, + '10a010-0101': error_invalid, + '101010-0\xe401': error_invalid, + '101010b0101': error_invalid, + } + self.assertFieldOutput(FISocialSecurityNumber, valid, invalid) ->>> f.clean(None) -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f = FISocialSecurityNumber(required=False) ->>> f.clean('010101-0101') -u'010101-0101' ->>> f.clean(None) -u'' ->>> f.clean('') -u'' -""" diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index f44f81d12a..11b4b5c15d 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/tests/regressiontests/forms/localflavortests.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from localflavor.cz import tests as localflavor_cz_tests -from localflavor.fi import tests as localflavor_fi_tests from localflavor.fr import tests as localflavor_fr_tests from localflavor.generic import tests as localflavor_generic_tests from localflavor.id import tests as localflavor_id_tests @@ -30,13 +29,13 @@ from localflavor.ch import CHLocalFlavorTests from localflavor.cl import CLLocalFlavorTests from localflavor.de import DELocalFlavorTests from localflavor.es import ESLocalFlavorTests +from localflavor.fi import FILocalFlavorTests from localflavor.il import ILLocalFlavorTests from localflavor.tr import TRLocalFlavorTests __test__ = { 'localflavor_cz_tests': localflavor_cz_tests, - 'localflavor_fi_tests': localflavor_fi_tests, 'localflavor_fr_tests': localflavor_fr_tests, 'localflavor_generic_tests': localflavor_generic_tests, 'localflavor_id_tests': localflavor_id_tests, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 0ebdcadec4..ea3ea78ef6 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -23,6 +23,7 @@ from regressiontests.forms.localflavortests import ( CLLocalFlavorTests, DELocalFlavorTests, ESLocalFlavorTests, + FILocalFlavorTests, ILLocalFlavorTests, TRLocalFlavorTests, ) |
