PageRenderTime 27ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/ar.py

https://code.google.com/p/mango-py/
Python | 99 lines | 96 code | 3 blank | 0 comment | 5 complexity | dd4e5135357bccee88ebbc89e6892f98 MD5 | raw file
 1from django.contrib.localflavor.ar.forms import (ARProvinceSelect,
 2    ARPostalCodeField, ARDNIField, ARCUITField)
 3
 4from utils import LocalFlavorTestCase
 5
 6
 7class ARLocalFlavorTests(LocalFlavorTestCase):
 8    def test_ARProvinceSelect(self):
 9        f = ARProvinceSelect()
10        out = u'''<select name="provincias">
11<option value="B">Buenos Aires</option>
12<option value="K">Catamarca</option>
13<option value="H">Chaco</option>
14<option value="U">Chubut</option>
15<option value="C">Ciudad Aut\xf3noma de Buenos Aires</option>
16<option value="X">C\xf3rdoba</option>
17<option value="W">Corrientes</option>
18<option value="E">Entre R\xedos</option>
19<option value="P">Formosa</option>
20<option value="Y">Jujuy</option>
21<option value="L">La Pampa</option>
22<option value="F">La Rioja</option>
23<option value="M">Mendoza</option>
24<option value="N">Misiones</option>
25<option value="Q">Neuqu\xe9n</option>
26<option value="R">R\xedo Negro</option>
27<option value="A" selected="selected">Salta</option>
28<option value="J">San Juan</option>
29<option value="D">San Luis</option>
30<option value="Z">Santa Cruz</option>
31<option value="S">Santa Fe</option>
32<option value="G">Santiago del Estero</option>
33<option value="V">Tierra del Fuego, Ant\xe1rtida e Islas del Atl\xe1ntico Sur</option>
34<option value="T">Tucum\xe1n</option>
35</select>'''
36        self.assertEqual(f.render('provincias', 'A'), out)
37
38    def test_ARPostalCodeField(self):
39        error_format = [u'Enter a postal code in the format NNNN or ANNNNAAA.']
40        error_atmost = [u'Ensure this value has at most 8 characters (it has 9).']
41        error_atleast = [u'Ensure this value has at least 4 characters (it has 3).']
42        valid = {
43            '5000': '5000',
44            'C1064AAB': 'C1064AAB',
45            'c1064AAB': 'C1064AAB',
46            'C1064aab': 'C1064AAB',
47            '4400': '4400',
48            u'C1064AAB': 'C1064AAB',
49        }
50        invalid = {
51            'C1064AABB': error_atmost + error_format,
52            'C1064AA': error_format,
53            'C1064AB': error_format,
54            '106AAB': error_format,
55            '500': error_atleast + error_format,
56            '5PPP': error_format,
57        }
58        self.assertFieldOutput(ARPostalCodeField, valid, invalid)
59
60    def test_ARDNIField(self):
61        error_length = [u'This field requires 7 or 8 digits.']
62        error_digitsonly = [u'This field requires only numbers.']
63        valid = {
64            '20123456': '20123456',
65            '20.123.456': '20123456',
66            u'20123456': '20123456',
67            u'20.123.456': '20123456',
68            '20.123456': '20123456',
69            '9123456': '9123456',
70            '9.123.456': '9123456',
71        }
72        invalid = {
73            '101234566': error_length,
74            'W0123456': error_digitsonly,
75            '10,123,456': error_digitsonly,
76        }
77        self.assertFieldOutput(ARDNIField, valid, invalid)
78
79    def test_ARCUITField(self):
80        error_format = [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.']
81        error_invalid = [u'Invalid CUIT.']
82        valid = {
83            '20-10123456-9': '20-10123456-9',
84            u'20-10123456-9': '20-10123456-9',
85            '27-10345678-4': '27-10345678-4',
86            '20101234569': '20-10123456-9',
87            '27103456784': '27-10345678-4',
88        }
89        invalid = {
90            '2-10123456-9': error_format,
91            '210123456-9': error_format,
92            '20-10123456': error_format,
93            '20-10123456-': error_format,
94             '20-10123456-5': error_invalid,
95            '2-10123456-9': error_format,
96             '27-10345678-1': error_invalid,
97             u'27-10345678-1': error_invalid,
98        }
99        self.assertFieldOutput(ARCUITField, valid, invalid)