PageRenderTime 122ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 55ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/ch.py

https://code.google.com/p/mango-py/
Python | 75 lines | 72 code | 3 blank | 0 comment | 5 complexity | 1a4dff478e199aef83eadd51064b369a MD5 | raw file
 1from django.contrib.localflavor.ch.forms import (CHZipCodeField,
 2    CHPhoneNumberField, CHIdentityCardNumberField, CHStateSelect)
 3
 4from utils import LocalFlavorTestCase
 5
 6
 7class CHLocalFlavorTests(LocalFlavorTestCase):
 8    def test_CHStateSelect(self):
 9        f = CHStateSelect()
10        out = u'''<select name="state">
11<option value="AG" selected="selected">Aargau</option>
12<option value="AI">Appenzell Innerrhoden</option>
13<option value="AR">Appenzell Ausserrhoden</option>
14<option value="BS">Basel-Stadt</option>
15<option value="BL">Basel-Land</option>
16<option value="BE">Berne</option>
17<option value="FR">Fribourg</option>
18<option value="GE">Geneva</option>
19<option value="GL">Glarus</option>
20<option value="GR">Graubuenden</option>
21<option value="JU">Jura</option>
22<option value="LU">Lucerne</option>
23<option value="NE">Neuchatel</option>
24<option value="NW">Nidwalden</option>
25<option value="OW">Obwalden</option>
26<option value="SH">Schaffhausen</option>
27<option value="SZ">Schwyz</option>
28<option value="SO">Solothurn</option>
29<option value="SG">St. Gallen</option>
30<option value="TG">Thurgau</option>
31<option value="TI">Ticino</option>
32<option value="UR">Uri</option>
33<option value="VS">Valais</option>
34<option value="VD">Vaud</option>
35<option value="ZG">Zug</option>
36<option value="ZH">Zurich</option>
37</select>'''
38        self.assertEqual(f.render('state', 'AG'), out)
39    
40    def test_CHZipCodeField(self):
41        error_format = [u'Enter a zip code in the format XXXX.']
42        valid = {
43            '1234': '1234',
44            '0000': '0000',
45        }
46        invalid = {
47            '800x': error_format,
48            '80 00': error_format,
49        }
50        self.assertFieldOutput(CHZipCodeField, valid, invalid)
51    
52    def test_CHPhoneNumberField(self):
53        error_format = [u'Phone numbers must be in 0XX XXX XX XX format.']
54        valid = {
55            '012 345 67 89': '012 345 67 89',
56            '0123456789': '012 345 67 89',
57        }
58        invalid = {
59            '01234567890': error_format,
60            '1234567890': error_format,
61        }
62        self.assertFieldOutput(CHPhoneNumberField, valid, invalid)
63    
64    def test_CHIdentityCardNumberField(self):
65        error_format = [u'Enter a valid Swiss identity or passport card number in X1234567<0 or 1234567890 format.']
66        valid = {
67            'C1234567<0': 'C1234567<0',
68            '2123456700': '2123456700',
69        }
70        invalid = {
71            'C1234567<1': error_format,
72            '2123456701': error_format,
73        }
74        self.assertFieldOutput(CHIdentityCardNumberField, valid, invalid)
75