PageRenderTime 30ms CodeModel.GetById 18ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/cl.py

https://code.google.com/p/mango-py/
Python | 57 lines | 54 code | 3 blank | 0 comment | 1 complexity | 0f86c44cb6143dfed45c1771bebd7edc MD5 | raw file
 1from django.contrib.localflavor.cl.forms import CLRutField, CLRegionSelect
 2from django.core.exceptions import ValidationError
 3
 4from utils import LocalFlavorTestCase
 5
 6
 7class CLLocalFlavorTests(LocalFlavorTestCase):
 8    def test_CLRegionSelect(self):
 9        f = CLRegionSelect()
10        out = u'''<select name="foo">
11<option value="RM">Regi\xf3n Metropolitana de Santiago</option>
12<option value="I">Regi\xf3n de Tarapac\xe1</option>
13<option value="II">Regi\xf3n de Antofagasta</option>
14<option value="III">Regi\xf3n de Atacama</option>
15<option value="IV">Regi\xf3n de Coquimbo</option>
16<option value="V">Regi\xf3n de Valpara\xedso</option>
17<option value="VI">Regi\xf3n del Libertador Bernardo O&#39;Higgins</option>
18<option value="VII">Regi\xf3n del Maule</option>
19<option value="VIII">Regi\xf3n del B\xedo B\xedo</option>
20<option value="IX">Regi\xf3n de la Araucan\xeda</option>
21<option value="X">Regi\xf3n de los Lagos</option>
22<option value="XI">Regi\xf3n de Ays\xe9n del General Carlos Ib\xe1\xf1ez del Campo</option>
23<option value="XII">Regi\xf3n de Magallanes y la Ant\xe1rtica Chilena</option>
24<option value="XIV">Regi\xf3n de Los R\xedos</option>
25<option value="XV">Regi\xf3n de Arica-Parinacota</option>
26</select>'''
27        self.assertEqual(f.render('foo', 'bar'), out)
28
29    def test_CLRutField(self):
30        error_invalid =  [u'The Chilean RUT is not valid.']
31        error_format = [u'Enter a valid Chilean RUT. The format is XX.XXX.XXX-X.']
32        valid = {
33            '11-6': '11-6',
34            '116': '11-6',
35            '767484100': '76.748.410-0',
36            '78.412.790-7': '78.412.790-7',
37            '8.334.6043': '8.334.604-3',
38            '76793310-K': '76.793.310-K',
39            '76793310-k': '76.793.310-K',
40        }
41        invalid = {
42            '11.111.111-0': error_invalid,
43            '111': error_invalid,
44        }
45        self.assertFieldOutput(CLRutField, valid, invalid)
46
47        # deal with special "Strict Mode".
48        invalid = {
49            '11-6': error_format,
50            '767484100': error_format,
51            '8.334.6043': error_format,
52            '76793310-K': error_format,
53            '11.111.111-0': error_invalid
54        }
55        self.assertFieldOutput(CLRutField,
56            {}, invalid, field_kwargs={"strict": True}
57        )