Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Converted Uruguayan localflavor doctests into unittests. We h…

…ave alwyas been at war with doctests. Thanks to Idan Gazit. Backport of [14955].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14979 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 989f59299c2476967a5ca94240ac860a4a79d087 1 parent 0c33a3a
@alex alex authored
View
90 tests/regressiontests/forms/localflavor/uy.py
@@ -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.']
-"""
View
3  tests/regressiontests/forms/localflavortests.py
@@ -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
@@ -30,11 +29,11 @@
from localflavor.sk import SKLocalFlavorTests
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,
}
View
1  tests/regressiontests/forms/tests/__init__.py
@@ -38,4 +38,5 @@
SKLocalFlavorTests,
UKLocalFlavorTests,
USLocalFlavorTests,
+ UYLocalFlavorTests,
)
Please sign in to comment.
Something went wrong with that request. Please try again.