From f4bc738e6b67a85e87d7abb7aa15ea37d5c701c5 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 18 Dec 2010 20:33:32 +0000 Subject: [PATCH] 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 --- tests/regressiontests/forms/localflavor/uy.py | 90 ++++++++++--------- .../regressiontests/forms/localflavortests.py | 3 +- tests/regressiontests/forms/tests/__init__.py | 1 + 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/tests/regressiontests/forms/localflavor/uy.py b/tests/regressiontests/forms/localflavor/uy.py index 057ab193f5..2b9e134362 100644 --- a/tests/regressiontests/forms/localflavor/uy.py +++ b/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'' -# UYCIField ################################################################### +class UYLocalFlavorTests(LocalFlavorTestCase): + def test_UYDepartmentSelect(self): + f = UYDepartamentSelect() + out = u'''''' + 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.'] -""" diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 02ec55f3d4..10ddf9abc5 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/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 @@ -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, } diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index c301ffe25e..2cc725b4e0 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -41,4 +41,5 @@ from regressiontests.forms.localflavortests import ( TRLocalFlavorTests, UKLocalFlavorTests, USLocalFlavorTests, + UYLocalFlavorTests, )