Converted Dutch 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@14948 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-12-18 20:32:17 +00:00
parent 79ea397b5d
commit 187a11e1f1
3 changed files with 58 additions and 68 deletions

View File

@ -1,72 +1,62 @@
# -*- coding: utf-8 -*- from django.contrib.localflavor.nl.forms import (NLPhoneNumberField,
# Tests for the contrib/localflavor/ NL form fields. NLZipCodeField, NLSoFiNumberField, NLProvinceSelect)
tests = r""" from utils import LocalFlavorTestCase
# NLPhoneNumberField ########################################################
>>> from django.contrib.localflavor.nl.forms import NLPhoneNumberField
>>> f = NLPhoneNumberField(required=False)
>>> f.clean('')
u''
>>> f.clean('012-3456789')
'012-3456789'
>>> f.clean('0123456789')
'0123456789'
>>> f.clean('+31-12-3456789')
'+31-12-3456789'
>>> f.clean('(0123) 456789')
'(0123) 456789'
>>> f.clean('foo')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid phone number']
# NLZipCodeField ############################################################ class NLLocalFlavorTests(LocalFlavorTestCase):
def test_NLProvinceSelect(self):
f = NLProvinceSelect()
out = u'''<select name="provinces">
<option value="DR">Drenthe</option>
<option value="FL">Flevoland</option>
<option value="FR">Friesland</option>
<option value="GL">Gelderland</option>
<option value="GR">Groningen</option>
<option value="LB">Limburg</option>
<option value="NB">Noord-Brabant</option>
<option value="NH">Noord-Holland</option>
<option value="OV" selected="selected">Overijssel</option>
<option value="UT">Utrecht</option>
<option value="ZE">Zeeland</option>
<option value="ZH">Zuid-Holland</option>
</select>'''
self.assertEqual(f.render('provinces', 'OV'), out)
>>> from django.contrib.localflavor.nl.forms import NLZipCodeField def test_NLPhoneNumberField(self):
>>> f = NLZipCodeField(required=False) error_invalid = [u'Enter a valid phone number']
>>> f.clean('') valid = {
u'' '012-3456789': '012-3456789',
>>> f.clean('1234ab') '0123456789': '0123456789',
u'1234 AB' '+31-12-3456789': '+31-12-3456789',
>>> f.clean('1234 ab') '(0123) 456789': '(0123) 456789',
u'1234 AB' }
>>> f.clean('1234 AB') invalid = {
u'1234 AB' 'foo': error_invalid,
>>> f.clean('0123AB') }
Traceback (most recent call last): self.assertFieldOutput(NLPhoneNumberField, valid, invalid)
...
ValidationError: [u'Enter a valid postal code']
>>> f.clean('foo')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid postal code']
# NLSoFiNumberField ######################################################### def test_NLZipCodeField(self):
error_invalid = [u'Enter a valid postal code']
valid = {
'1234ab': '1234 AB',
'1234 ab': '1234 AB',
'1234 AB': '1234 AB',
}
invalid = {
'0123AB': error_invalid,
'foo': error_invalid,
}
self.assertFieldOutput(NLZipCodeField, valid, invalid)
>>> from django.contrib.localflavor.nl.forms import NLSoFiNumberField def test_NLSoFiNumberField(self):
>>> f = NLSoFiNumberField(required=False) error_invalid = [u'Enter a valid SoFi number']
>>> f.clean('') valid = {
u'' '123456782': '123456782',
>>> f.clean('123456782') }
'123456782' invalid = {
>>> f.clean('000000000') '000000000': error_invalid,
Traceback (most recent call last): '123456789': error_invalid,
... 'foo': error_invalid,
ValidationError: [u'Enter a valid SoFi number'] }
>>> f.clean('123456789') self.assertFieldOutput(NLSoFiNumberField, valid, invalid)
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid SoFi number']
>>> f.clean('foo')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid SoFi number']
# NLProvinceSelect ##########################################################
>>> from django.contrib.localflavor.nl.forms import NLProvinceSelect
>>> s = NLProvinceSelect()
>>> s.render('provinces', 'OV')
u'<select name="provinces">\n<option value="DR">Drenthe</option>\n<option value="FL">Flevoland</option>\n<option value="FR">Friesland</option>\n<option value="GL">Gelderland</option>\n<option value="GR">Groningen</option>\n<option value="LB">Limburg</option>\n<option value="NB">Noord-Brabant</option>\n<option value="NH">Noord-Holland</option>\n<option value="OV" selected="selected">Overijssel</option>\n<option value="UT">Utrecht</option>\n<option value="ZE">Zeeland</option>\n<option value="ZH">Zuid-Holland</option>\n</select>'
"""

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from localflavor.cz import tests as localflavor_cz_tests from localflavor.cz import tests as localflavor_cz_tests
from localflavor.nl import tests as localflavor_nl_tests
from localflavor.pl import tests as localflavor_pl_tests from localflavor.pl import tests as localflavor_pl_tests
from localflavor.pt import tests as localflavor_pt_tests from localflavor.pt import tests as localflavor_pt_tests
from localflavor.ro import tests as localflavor_ro_tests from localflavor.ro import tests as localflavor_ro_tests
@ -31,12 +30,12 @@ from localflavor.is_ import ISLocalFlavorTests
from localflavor.it import ITLocalFlavorTests from localflavor.it import ITLocalFlavorTests
from localflavor.jp import JPLocalFlavorTests from localflavor.jp import JPLocalFlavorTests
from localflavor.kw import KWLocalFlavorTests from localflavor.kw import KWLocalFlavorTests
from localflavor.nl import NLLocalFlavorTests
from localflavor.tr import TRLocalFlavorTests from localflavor.tr import TRLocalFlavorTests
__test__ = { __test__ = {
'localflavor_cz_tests': localflavor_cz_tests, 'localflavor_cz_tests': localflavor_cz_tests,
'localflavor_nl_tests': localflavor_nl_tests,
'localflavor_pl_tests': localflavor_pl_tests, 'localflavor_pl_tests': localflavor_pl_tests,
'localflavor_pt_tests': localflavor_pt_tests, 'localflavor_pt_tests': localflavor_pt_tests,
'localflavor_ro_tests': localflavor_ro_tests, 'localflavor_ro_tests': localflavor_ro_tests,

View File

@ -33,5 +33,6 @@ from regressiontests.forms.localflavortests import (
ITLocalFlavorTests, ITLocalFlavorTests,
JPLocalFlavorTests, JPLocalFlavorTests,
KWLocalFlavorTests, KWLocalFlavorTests,
NLLocalFlavorTests,
TRLocalFlavorTests, TRLocalFlavorTests,
) )