PageRenderTime 30ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/es.py

https://code.google.com/p/mango-py/
Python | 172 lines | 169 code | 3 blank | 0 comment | 10 complexity | 935500b24672e78bec984b975603438f MD5 | raw file
  1from django.contrib.localflavor.es.forms import (ESPostalCodeField, ESPhoneNumberField,
  2    ESIdentityCardNumberField, ESCCCField, ESRegionSelect, ESProvinceSelect)
  3
  4from utils import LocalFlavorTestCase
  5
  6
  7class ESLocalFlavorTests(LocalFlavorTestCase):
  8    def test_ESRegionSelect(self):
  9        f = ESRegionSelect()
 10        out = u'''<select name="regions">
 11<option value="AN">Andalusia</option>
 12<option value="AR">Aragon</option>
 13<option value="O">Principality of Asturias</option>
 14<option value="IB">Balearic Islands</option>
 15<option value="PV">Basque Country</option>
 16<option value="CN">Canary Islands</option>
 17<option value="S">Cantabria</option>
 18<option value="CM">Castile-La Mancha</option>
 19<option value="CL">Castile and Leon</option>
 20<option value="CT" selected="selected">Catalonia</option>
 21<option value="EX">Extremadura</option>
 22<option value="GA">Galicia</option>
 23<option value="LO">La Rioja</option>
 24<option value="M">Madrid</option>
 25<option value="MU">Region of Murcia</option>
 26<option value="NA">Foral Community of Navarre</option>
 27<option value="VC">Valencian Community</option>
 28</select>'''
 29        self.assertEqual(f.render('regions', 'CT'), out)
 30
 31    def test_ESProvinceSelect(self):
 32        f = ESProvinceSelect()
 33        out = u'''<select name="provinces">
 34<option value="01">Arava</option>
 35<option value="02">Albacete</option>
 36<option value="03">Alacant</option>
 37<option value="04">Almeria</option>
 38<option value="05">Avila</option>
 39<option value="06">Badajoz</option>
 40<option value="07">Illes Balears</option>
 41<option value="08" selected="selected">Barcelona</option>
 42<option value="09">Burgos</option>
 43<option value="10">Caceres</option>
 44<option value="11">Cadiz</option>
 45<option value="12">Castello</option>
 46<option value="13">Ciudad Real</option>
 47<option value="14">Cordoba</option>
 48<option value="15">A Coruna</option>
 49<option value="16">Cuenca</option>
 50<option value="17">Girona</option>
 51<option value="18">Granada</option>
 52<option value="19">Guadalajara</option>
 53<option value="20">Guipuzkoa</option>
 54<option value="21">Huelva</option>
 55<option value="22">Huesca</option>
 56<option value="23">Jaen</option>
 57<option value="24">Leon</option>
 58<option value="25">Lleida</option>
 59<option value="26">La Rioja</option>
 60<option value="27">Lugo</option>
 61<option value="28">Madrid</option>
 62<option value="29">Malaga</option>
 63<option value="30">Murcia</option>
 64<option value="31">Navarre</option>
 65<option value="32">Ourense</option>
 66<option value="33">Asturias</option>
 67<option value="34">Palencia</option>
 68<option value="35">Las Palmas</option>
 69<option value="36">Pontevedra</option>
 70<option value="37">Salamanca</option>
 71<option value="38">Santa Cruz de Tenerife</option>
 72<option value="39">Cantabria</option>
 73<option value="40">Segovia</option>
 74<option value="41">Seville</option>
 75<option value="42">Soria</option>
 76<option value="43">Tarragona</option>
 77<option value="44">Teruel</option>
 78<option value="45">Toledo</option>
 79<option value="46">Valencia</option>
 80<option value="47">Valladolid</option>
 81<option value="48">Bizkaia</option>
 82<option value="49">Zamora</option>
 83<option value="50">Zaragoza</option>
 84<option value="51">Ceuta</option>
 85<option value="52">Melilla</option>
 86</select>'''
 87        self.assertEqual(f.render('provinces', '08'), out)
 88
 89    def test_ESPostalCodeField(self):
 90        error_invalid = [u'Enter a valid postal code in the range and format 01XXX - 52XXX.']
 91        valid = {
 92            '08028': '08028',
 93            '28080': '28080',
 94        }
 95        invalid = {
 96            '53001': error_invalid,
 97            '0801': error_invalid,
 98            '080001': error_invalid,
 99            '00999': error_invalid,
100            '08 01': error_invalid,
101            '08A01': error_invalid,
102        }
103        self.assertFieldOutput(ESPostalCodeField, valid, invalid)
104
105    def test_ESPhoneNumberField(self):
106        error_invalid = [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.']
107        valid = {
108            '650010101': '650010101',
109            '931234567': '931234567',
110            '800123123': '800123123',
111        }
112        invalid = {
113            '555555555': error_invalid,
114            '789789789': error_invalid,
115            '99123123': error_invalid,
116            '9999123123': error_invalid,
117        }
118        self.assertFieldOutput(ESPhoneNumberField, valid, invalid)
119
120    def test_ESIdentityCardNumberField(self):
121        error_invalid = [u'Please enter a valid NIF, NIE, or CIF.']
122        error_checksum_nif = [u'Invalid checksum for NIF.']
123        error_checksum_nie = [u'Invalid checksum for NIE.']
124        error_checksum_cif = [u'Invalid checksum for CIF.']
125        valid = {
126            '78699688J': '78699688J',
127            '78699688-J': '78699688J',
128            '78699688 J': '78699688J',
129            '78699688 j': '78699688J',
130            'X0901797J': 'X0901797J',
131            'X-6124387-Q': 'X6124387Q',
132            'X 0012953 G': 'X0012953G',
133            'x-3287690-r': 'X3287690R',
134            't-03287690r': 'T03287690R',
135            'P2907500I': 'P2907500I',
136            'B38790911': 'B38790911',
137            'B31234560': 'B31234560',
138            'B-3879091A': 'B3879091A',
139            'B 38790911': 'B38790911',
140            'P-3900800-H': 'P3900800H',
141            'P 39008008': 'P39008008',
142            'C-28795565': 'C28795565',
143            'C 2879556E': 'C2879556E',
144        }
145        invalid = {
146            '78699688T': error_checksum_nif,
147            'X-03287690': error_invalid,
148            'X-03287690-T': error_checksum_nie,
149            'B 38790917': error_checksum_cif,
150            'C28795567': error_checksum_cif,
151            'I38790911': error_invalid,
152            '78699688-2': error_invalid,
153        }
154        self.assertFieldOutput(ESIdentityCardNumberField, valid, invalid)
155    
156    def test_ESCCCField(self):
157        error_invalid = [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.']
158        error_checksum = [u'Invalid checksum for bank account number.']
159        valid = {
160            '20770338793100254321': '20770338793100254321',
161            '2077 0338 79 3100254321': '2077 0338 79 3100254321',
162            '2077-0338-79-3100254321': '2077-0338-79-3100254321',
163        }
164        invalid = {
165            '2077.0338.79.3100254321': error_invalid,
166            '2077-0338-78-3100254321': error_checksum,
167            '2077-0338-89-3100254321': error_checksum,
168            '2077-03-3879-3100254321': error_invalid,
169        }
170        self.assertFieldOutput(ESCCCField, valid, invalid)
171
172