Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converted Swiss localflavor doctests to unittests. Thanks to Idan Gaz…

…it for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14935 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7fdfec7a3c145f2bd54a12f891810a8b5cfe8d03 1 parent 3ed8584
@alex alex authored
View
125 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'''<select name="state">
+<option value="AG" selected="selected">Aargau</option>
+<option value="AI">Appenzell Innerrhoden</option>
+<option value="AR">Appenzell Ausserrhoden</option>
+<option value="BS">Basel-Stadt</option>
+<option value="BL">Basel-Land</option>
+<option value="BE">Berne</option>
+<option value="FR">Fribourg</option>
+<option value="GE">Geneva</option>
+<option value="GL">Glarus</option>
+<option value="GR">Graubuenden</option>
+<option value="JU">Jura</option>
+<option value="LU">Lucerne</option>
+<option value="NE">Neuchatel</option>
+<option value="NW">Nidwalden</option>
+<option value="OW">Obwalden</option>
+<option value="SH">Schaffhausen</option>
+<option value="SZ">Schwyz</option>
+<option value="SO">Solothurn</option>
+<option value="SG">St. Gallen</option>
+<option value="TG">Thurgau</option>
+<option value="TI">Ticino</option>
+<option value="UR">Uri</option>
+<option value="VS">Valais</option>
+<option value="VD">Vaud</option>
+<option value="ZG">Zug</option>
+<option value="ZH">Zurich</option>
+</select>'''
+ 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'<select name="state">\n<option value="AG" selected="selected">Aargau</option>\n<option value="AI">Appenzell Innerrhoden</option>\n<option value="AR">Appenzell Ausserrhoden</option>\n<option value="BS">Basel-Stadt</option>\n<option value="BL">Basel-Land</option>\n<option value="BE">Berne</option>\n<option value="FR">Fribourg</option>\n<option value="GE">Geneva</option>\n<option value="GL">Glarus</option>\n<option value="GR">Graubuenden</option>\n<option value="JU">Jura</option>\n<option value="LU">Lucerne</option>\n<option value="NE">Neuchatel</option>\n<option value="NW">Nidwalden</option>\n<option value="OW">Obwalden</option>\n<option value="SH">Schaffhausen</option>\n<option value="SZ">Schwyz</option>\n<option value="SO">Solothurn</option>\n<option value="SG">St. Gallen</option>\n<option value="TG">Thurgau</option>\n<option value="TI">Ticino</option>\n<option value="UR">Uri</option>\n<option value="VS">Valais</option>\n<option value="VD">Vaud</option>\n<option value="ZG">Zug</option>\n<option value="ZH">Zurich</option>\n</select>'
-"""
View
3  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.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,
View
1  tests/regressiontests/forms/tests/__init__.py
@@ -19,6 +19,7 @@
BELocalFlavorTests,
BRLocalFlavorTests,
CALocalFlavorTests,
+ CHLocalFlavorTests,
DELocalFlavorTests,
ILLocalFlavorTests,
TRLocalFlavorTests,
Please sign in to comment.
Something went wrong with that request. Please try again.