diff --git a/tests/regressiontests/forms/localflavor/fi.py b/tests/regressiontests/forms/localflavor/fi.py index cc3723e4a23..161eb1743bf 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' @@ -395,49 +350,33 @@ u'' +''' + self.assertEquals(f.render('municipalities', 'turku'), out) + 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) -# FISocialSecurityNumber ############################################################## + 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) ->>> 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.'] - ->>> 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 f44f81d12a2..11b4b5c15de 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 0ebdcadec46..ea3ea78ef61 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, )