Converted Uruguayan localflavor doctests into unittests. We have alwyas been at war with doctests. Thanks to Idan Gazit.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14955 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
dec7e2bf2d
commit
f4bc738e6b
|
@ -1,46 +1,52 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Tests for the contrib/localflavor/ UY form fields.
|
||||
from django.contrib.localflavor.uy.forms import UYDepartamentSelect, UYCIField
|
||||
from django.contrib.localflavor.uy.util import get_validation_digit
|
||||
|
||||
tests = r"""
|
||||
# UYDepartamentSelect #########################################################
|
||||
from utils import LocalFlavorTestCase
|
||||
|
||||
>>> from django.contrib.localflavor.uy.forms import UYDepartamentSelect
|
||||
>>> f = UYDepartamentSelect()
|
||||
>>> f.render('departamentos', 'S')
|
||||
u'<select name="departamentos">\n<option value="G">Artigas</option>\n<option value="A">Canelones</option>\n<option value="E">Cerro Largo</option>\n<option value="L">Colonia</option>\n<option value="Q">Durazno</option>\n<option value="N">Flores</option>\n<option value="O">Florida</option>\n<option value="P">Lavalleja</option>\n<option value="B">Maldonado</option>\n<option value="S" selected="selected">Montevideo</option>\n<option value="I">Paysand\xfa</option>\n<option value="J">R\xedo Negro</option>\n<option value="F">Rivera</option>\n<option value="C">Rocha</option>\n<option value="H">Salto</option>\n<option value="M">San Jos\xe9</option>\n<option value="K">Soriano</option>\n<option value="R">Tacuaremb\xf3</option>\n<option value="D">Treinta y Tres</option>\n</select>'
|
||||
|
||||
# UYCIField ###################################################################
|
||||
class UYLocalFlavorTests(LocalFlavorTestCase):
|
||||
def test_UYDepartmentSelect(self):
|
||||
f = UYDepartamentSelect()
|
||||
out = u'''<select name="departamentos">
|
||||
<option value="G">Artigas</option>
|
||||
<option value="A">Canelones</option>
|
||||
<option value="E">Cerro Largo</option>
|
||||
<option value="L">Colonia</option>
|
||||
<option value="Q">Durazno</option>
|
||||
<option value="N">Flores</option>
|
||||
<option value="O">Florida</option>
|
||||
<option value="P">Lavalleja</option>
|
||||
<option value="B">Maldonado</option>
|
||||
<option value="S" selected="selected">Montevideo</option>
|
||||
<option value="I">Paysand\xfa</option>
|
||||
<option value="J">R\xedo Negro</option>
|
||||
<option value="F">Rivera</option>
|
||||
<option value="C">Rocha</option>
|
||||
<option value="H">Salto</option>
|
||||
<option value="M">San Jos\xe9</option>
|
||||
<option value="K">Soriano</option>
|
||||
<option value="R">Tacuaremb\xf3</option>
|
||||
<option value="D">Treinta y Tres</option>
|
||||
</select>'''
|
||||
self.assertEqual(f.render('departamentos', 'S'), out)
|
||||
|
||||
def test_UYCIField(self):
|
||||
error_format = [u'Enter a valid CI number in X.XXX.XXX-X,XXXXXXX-X or XXXXXXXX format.']
|
||||
error_invalid = [u'Enter a valid CI number.']
|
||||
valid = {
|
||||
'4098053': '4098053',
|
||||
'409805-3': '409805-3',
|
||||
'409.805-3': '409.805-3',
|
||||
'10054112': '10054112',
|
||||
'1005411-2': '1005411-2',
|
||||
'1.005.411-2': '1.005.411-2',
|
||||
}
|
||||
invalid = {
|
||||
'foo': [u'Enter a valid CI number in X.XXX.XXX-X,XXXXXXX-X or XXXXXXXX format.'],
|
||||
'409805-2': [u'Enter a valid CI number.'],
|
||||
'1.005.411-5': [u'Enter a valid CI number.'],
|
||||
}
|
||||
self.assertFieldOutput(UYCIField, valid, invalid)
|
||||
self.assertEqual(get_validation_digit(409805), 3)
|
||||
self.assertEqual(get_validation_digit(1005411), 2)
|
||||
|
||||
>>> from django.contrib.localflavor.uy.util import get_validation_digit
|
||||
>>> get_validation_digit(409805) == 3
|
||||
True
|
||||
>>> get_validation_digit(1005411) == 2
|
||||
True
|
||||
|
||||
>>> from django.contrib.localflavor.uy.forms import UYCIField
|
||||
>>> f = UYCIField()
|
||||
>>> f.clean('4098053')
|
||||
u'4098053'
|
||||
>>> f.clean('409805-3')
|
||||
u'409805-3'
|
||||
>>> f.clean('409.805-3')
|
||||
u'409.805-3'
|
||||
>>> f.clean('10054112')
|
||||
u'10054112'
|
||||
>>> f.clean('1005411-2')
|
||||
u'1005411-2'
|
||||
>>> f.clean('1.005.411-2')
|
||||
u'1.005.411-2'
|
||||
>>> f.clean('foo')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid CI number in X.XXX.XXX-X,XXXXXXX-X or XXXXXXXX format.']
|
||||
>>> f.clean('409805-2')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid CI number.']
|
||||
>>> f.clean('1.005.411-5')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid CI number.']
|
||||
"""
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from localflavor.cz import tests as localflavor_cz_tests
|
||||
from localflavor.se import tests as localflavor_se_tests
|
||||
from localflavor.uy import tests as localflavor_uy_tests
|
||||
from localflavor.za import tests as localflavor_za_tests
|
||||
|
||||
from localflavor.ar import ARLocalFlavorTests
|
||||
|
@ -32,11 +31,11 @@ from localflavor.sk import SKLocalFlavorTests
|
|||
from localflavor.tr import TRLocalFlavorTests
|
||||
from localflavor.uk import UKLocalFlavorTests
|
||||
from localflavor.us import USLocalFlavorTests
|
||||
from localflavor.uy import UYLocalFlavorTests
|
||||
|
||||
|
||||
__test__ = {
|
||||
'localflavor_cz_tests': localflavor_cz_tests,
|
||||
'localflavor_se_tests': localflavor_se_tests,
|
||||
'localflavor_uy_tests': localflavor_uy_tests,
|
||||
'localflavor_za_tests': localflavor_za_tests,
|
||||
}
|
||||
|
|
|
@ -41,4 +41,5 @@ from regressiontests.forms.localflavortests import (
|
|||
TRLocalFlavorTests,
|
||||
UKLocalFlavorTests,
|
||||
USLocalFlavorTests,
|
||||
UYLocalFlavorTests,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue