diff --git a/tests/regressiontests/forms/localflavor/ch.py b/tests/regressiontests/forms/localflavor/ch.py index b4f8e7d667..c67bfcfdf8 100644 --- a/tests/regressiontests/forms/localflavor/ch.py +++ b/tests/regressiontests/forms/localflavor/ch.py @@ -1,58 +1,75 @@ -# -*- coding: utf-8 -*- -# Tests for the contrib/localflavor/ CH form fields. +from django.contrib.localflavor.ch.forms import (CHZipCodeField, + CHPhoneNumberField, CHIdentityCardNumberField, CHStateSelect) -tests = r""" -# CHZipCodeField ############################################################ +from utils import LocalFlavorTestCase ->>> from django.contrib.localflavor.ch.forms import CHZipCodeField ->>> f = CHZipCodeField() ->>> f.clean('800x') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX.'] ->>> f.clean('80 00') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX.'] ->>> f.clean('8000') -u'8000' -# CHPhoneNumberField ######################################################## +class CHLocalFlavorTests(LocalFlavorTestCase): + def test_CHStateSelect(self): + f = CHStateSelect() + out = u'''''' + self.assertEqual(f.render('state', 'AG'), out) + + def test_CHZipCodeField(self): + error_format = [u'Enter a zip code in the format XXXX.'] + valid = { + '1234': '1234', + '0000': '0000', + } + invalid = { + '800x': error_format, + '80 00': error_format, + } + self.assertFieldOutput(CHZipCodeField, valid, invalid) + + def test_CHPhoneNumberField(self): + error_format = [u'Phone numbers must be in 0XX XXX XX XX format.'] + valid = { + '012 345 67 89': '012 345 67 89', + '0123456789': '012 345 67 89', + } + invalid = { + '01234567890': error_format, + '1234567890': error_format, + } + self.assertFieldOutput(CHPhoneNumberField, valid, invalid) + + def test_CHIdentityCardNumberField(self): + error_format = [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'] + valid = { + 'C1234567<0': 'C1234567<0', + '2123456700': '2123456700', + } + invalid = { + 'C1234567<1': error_format, + '2123456701': error_format, + } + self.assertFieldOutput(CHIdentityCardNumberField, valid, invalid) ->>> from django.contrib.localflavor.ch.forms import CHPhoneNumberField ->>> f = CHPhoneNumberField() ->>> f.clean('01234567890') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0XX XXX XX XX format.'] ->>> f.clean('1234567890') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must be in 0XX XXX XX XX format.'] ->>> f.clean('0123456789') -u'012 345 67 89' - -# CHIdentityCardNumberField ################################################# - ->>> from django.contrib.localflavor.ch.forms import CHIdentityCardNumberField ->>> f = CHIdentityCardNumberField() ->>> f.clean('C1234567<0') -u'C1234567<0' ->>> f.clean('C1234567<1') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'] ->>> f.clean('2123456700') -u'2123456700' ->>> f.clean('2123456701') -Traceback (most recent call last): -... -ValidationError: [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.'] - -# CHStateSelect ############################################################# - ->>> from django.contrib.localflavor.ch.forms import CHStateSelect ->>> w = CHStateSelect() ->>> w.render('state', 'AG') -u'' -""" diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 51d51765ad..7818025ae2 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/tests/regressiontests/forms/localflavortests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from localflavor.ch import tests as localflavor_ch_tests from localflavor.cl import tests as localflavor_cl_tests from localflavor.cz import tests as localflavor_cz_tests from localflavor.es import tests as localflavor_es_tests @@ -30,12 +29,12 @@ from localflavor.au import AULocalFlavorTests from localflavor.be import BELocalFlavorTests from localflavor.br import BRLocalFlavorTests from localflavor.ca import CALocalFlavorTests +from localflavor.ch import CHLocalFlavorTests from localflavor.il import ILLocalFlavorTests from localflavor.tr import TRLocalFlavorTests __test__ = { - 'localflavor_ch_tests': localflavor_ch_tests, 'localflavor_cl_tests': localflavor_cl_tests, 'localflavor_cz_tests': localflavor_cz_tests, 'localflavor_es_tests': localflavor_es_tests, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index 9969a68628..c5fc92c85b 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -19,6 +19,7 @@ from regressiontests.forms.localflavortests import ( BELocalFlavorTests, BRLocalFlavorTests, CALocalFlavorTests, + CHLocalFlavorTests, DELocalFlavorTests, ILLocalFlavorTests, TRLocalFlavorTests,