Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Converted Finnish localflavor doctests to unittests. We have …

…always been at war with doctests. Thanks to Idan Gazit. Backport of [14938].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14963 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aaaaa831fe127ae6b80aa6e8709e0c44d417f4f5 1 parent 812b1b2
@alex alex authored
View
129 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 @@
<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''
-"""
View
3  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,11 +29,11 @@
from localflavor.cl import CLLocalFlavorTests
from localflavor.de import DELocalFlavorTests
from localflavor.es import ESLocalFlavorTests
+from localflavor.fi import FILocalFlavorTests
__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,
View
1  tests/regressiontests/forms/tests/__init__.py
@@ -22,4 +22,5 @@
CLLocalFlavorTests,
DELocalFlavorTests,
ESLocalFlavorTests,
+ FILocalFlavorTests,
)
Please sign in to comment.
Something went wrong with that request. Please try again.