| 1 | # -*- coding: utf-8 -*- |
| 2 | # Tests for the contrib/localflavor/ ES form fields. |
| 3 | |
| 4 | tests = r""" |
| 5 | # ESPostalCodeField ############################################################## |
| 6 | |
| 7 | ESPostalCodeField validates that data is a five-digit spanish postal code. |
| 8 | >>> from django.contrib.localflavor.es.forms import ESPostalCodeField |
| 9 | >>> f = ESPostalCodeField() |
| 10 | >>> f.clean('08028') |
| 11 | u'08028' |
| 12 | >>> f.clean('28080') |
| 13 | u'28080' |
| 14 | >>> f.clean('53001') |
| 15 | Traceback (most recent call last): |
| 16 | ... |
| 17 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 18 | >>> f.clean('0801') |
| 19 | Traceback (most recent call last): |
| 20 | ... |
| 21 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 22 | >>> f.clean('080001') |
| 23 | Traceback (most recent call last): |
| 24 | ... |
| 25 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 26 | >>> f.clean('00999') |
| 27 | Traceback (most recent call last): |
| 28 | ... |
| 29 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 30 | >>> f.clean('08 01') |
| 31 | Traceback (most recent call last): |
| 32 | ... |
| 33 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 34 | >>> f.clean('08A01') |
| 35 | Traceback (most recent call last): |
| 36 | ... |
| 37 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 38 | >>> f.clean('') |
| 39 | Traceback (most recent call last): |
| 40 | ... |
| 41 | ValidationError: [u'This field is required.'] |
| 42 | |
| 43 | >>> f = ESPostalCodeField(required=False) |
| 44 | >>> f.clean('08028') |
| 45 | u'08028' |
| 46 | >>> f.clean('28080') |
| 47 | u'28080' |
| 48 | >>> f.clean('53001') |
| 49 | Traceback (most recent call last): |
| 50 | ... |
| 51 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 52 | >>> f.clean('0801') |
| 53 | Traceback (most recent call last): |
| 54 | ... |
| 55 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 56 | >>> f.clean('080001') |
| 57 | Traceback (most recent call last): |
| 58 | ... |
| 59 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 60 | >>> f.clean('00999') |
| 61 | Traceback (most recent call last): |
| 62 | ... |
| 63 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 64 | >>> f.clean('08 01') |
| 65 | Traceback (most recent call last): |
| 66 | ... |
| 67 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 68 | >>> f.clean('08A01') |
| 69 | Traceback (most recent call last): |
| 70 | ... |
| 71 | ValidationError: [u'Enter a valid postal code in the range and format 01XXX - 52XXX.'] |
| 72 | >>> f.clean('') |
| 73 | u'' |
| 74 | |
| 75 | # ESPhoneNumberField ############################################################## |
| 76 | |
| 77 | ESPhoneNumberField validates that data is a nine-digit spanish phone number. |
| 78 | >>> from django.contrib.localflavor.es.forms import ESPhoneNumberField |
| 79 | >>> f = ESPhoneNumberField() |
| 80 | >>> f.clean('650010101') |
| 81 | u'650010101' |
| 82 | >>> f.clean('931234567') |
| 83 | u'931234567' |
| 84 | >>> f.clean('800123123') |
| 85 | u'800123123' |
| 86 | >>> f.clean('555555555') |
| 87 | Traceback (most recent call last): |
| 88 | ... |
| 89 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 90 | >>> f.clean('789789789') |
| 91 | Traceback (most recent call last): |
| 92 | ... |
| 93 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 94 | >>> f.clean('99123123') |
| 95 | Traceback (most recent call last): |
| 96 | ... |
| 97 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 98 | >>> f.clean('9999123123') |
| 99 | Traceback (most recent call last): |
| 100 | ... |
| 101 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 102 | >>> f.clean('') |
| 103 | Traceback (most recent call last): |
| 104 | ... |
| 105 | ValidationError: [u'This field is required.'] |
| 106 | |
| 107 | >>> f = ESPhoneNumberField(required=False) |
| 108 | >>> f.clean('650010101') |
| 109 | u'650010101' |
| 110 | >>> f.clean('931234567') |
| 111 | u'931234567' |
| 112 | >>> f.clean('800123123') |
| 113 | u'800123123' |
| 114 | >>> f.clean('555555555') |
| 115 | Traceback (most recent call last): |
| 116 | ... |
| 117 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 118 | >>> f.clean('789789789') |
| 119 | Traceback (most recent call last): |
| 120 | ... |
| 121 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 122 | >>> f.clean('99123123') |
| 123 | Traceback (most recent call last): |
| 124 | ... |
| 125 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 126 | >>> f.clean('9999123123') |
| 127 | Traceback (most recent call last): |
| 128 | ... |
| 129 | ValidationError: [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.'] |
| 130 | >>> f.clean('') |
| 131 | u'' |
| 132 | |
| 133 | # ESIdentityCardNumberField ############################################################## |
| 134 | |
| 135 | ESIdentityCardNumberField validates that data is a identification spanish code for companies or individuals (CIF, NIF or NIE). |
| 136 | >>> from django.contrib.localflavor.es.forms import ESIdentityCardNumberField |
| 137 | >>> f = ESIdentityCardNumberField() |
| 138 | >>> f.clean('78699688J') |
| 139 | '78699688J' |
| 140 | >>> f.clean('78699688-J') |
| 141 | '78699688J' |
| 142 | >>> f.clean('78699688 J') |
| 143 | '78699688J' |
| 144 | >>> f.clean('78699688 j') |
| 145 | '78699688J' |
| 146 | >>> f.clean('78699688T') |
| 147 | Traceback (most recent call last): |
| 148 | ... |
| 149 | ValidationError: [u'Invalid checksum for NIF.'] |
| 150 | >>> f.clean('X0901797J') |
| 151 | 'X0901797J' |
| 152 | >>> f.clean('X-6124387-Q') |
| 153 | 'X6124387Q' |
| 154 | >>> f.clean('X 0012953 G') |
| 155 | 'X0012953G' |
| 156 | >>> f.clean('x-3287690-r') |
| 157 | 'X3287690R' |
| 158 | >>> f.clean('t-03287690r') |
| 159 | 'T03287690R' |
| 160 | >>> f.clean('X-03287690') |
| 161 | Traceback (most recent call last): |
| 162 | ... |
| 163 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 164 | >>> f.clean('X-03287690-T') |
| 165 | Traceback (most recent call last): |
| 166 | ... |
| 167 | ValidationError: [u'Invalid checksum for NIE.'] |
| 168 | >>> f.clean('B38790911') |
| 169 | 'B38790911' |
| 170 | >>> f.clean('B-3879091A') |
| 171 | 'B3879091A' |
| 172 | >>> f.clean('B 38790917') |
| 173 | Traceback (most recent call last): |
| 174 | ... |
| 175 | ValidationError: [u'Invalid checksum for CIF.'] |
| 176 | >>> f.clean('B 38790911') |
| 177 | 'B38790911' |
| 178 | >>> f.clean('P-3900800-H') |
| 179 | 'P3900800H' |
| 180 | >>> f.clean('P 39008008') |
| 181 | 'P39008008' |
| 182 | >>> f.clean('C-28795565') |
| 183 | 'C28795565' |
| 184 | >>> f.clean('C 2879556E') |
| 185 | 'C2879556E' |
| 186 | >>> f.clean('C28795567') |
| 187 | Traceback (most recent call last): |
| 188 | ... |
| 189 | ValidationError: [u'Invalid checksum for CIF.'] |
| 190 | >>> f.clean('I38790911') |
| 191 | Traceback (most recent call last): |
| 192 | ... |
| 193 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 194 | >>> f.clean('78699688-2') |
| 195 | Traceback (most recent call last): |
| 196 | ... |
| 197 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 198 | >>> f.clean('') |
| 199 | Traceback (most recent call last): |
| 200 | ... |
| 201 | ValidationError: [u'This field is required.'] |
| 202 | |
| 203 | >>> f = ESIdentityCardNumberField(required=False) |
| 204 | >>> f.clean('78699688J') |
| 205 | '78699688J' |
| 206 | >>> f.clean('78699688-J') |
| 207 | '78699688J' |
| 208 | >>> f.clean('78699688 J') |
| 209 | '78699688J' |
| 210 | >>> f.clean('78699688 j') |
| 211 | '78699688J' |
| 212 | >>> f.clean('78699688T') |
| 213 | Traceback (most recent call last): |
| 214 | ... |
| 215 | ValidationError: [u'Invalid checksum for NIF.'] |
| 216 | >>> f.clean('X0901797J') |
| 217 | 'X0901797J' |
| 218 | >>> f.clean('X-6124387-Q') |
| 219 | 'X6124387Q' |
| 220 | >>> f.clean('X 0012953 G') |
| 221 | 'X0012953G' |
| 222 | >>> f.clean('x-3287690-r') |
| 223 | 'X3287690R' |
| 224 | >>> f.clean('t-03287690r') |
| 225 | 'T03287690R' |
| 226 | >>> f.clean('X-03287690') |
| 227 | Traceback (most recent call last): |
| 228 | ... |
| 229 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 230 | >>> f.clean('X-03287690-T') |
| 231 | Traceback (most recent call last): |
| 232 | ... |
| 233 | ValidationError: [u'Invalid checksum for NIE.'] |
| 234 | >>> f.clean('B38790911') |
| 235 | 'B38790911' |
| 236 | >>> f.clean('B-3879091A') |
| 237 | 'B3879091A' |
| 238 | >>> f.clean('B 38790917') |
| 239 | Traceback (most recent call last): |
| 240 | ... |
| 241 | ValidationError: [u'Invalid checksum for CIF.'] |
| 242 | >>> f.clean('B 38790911') |
| 243 | 'B38790911' |
| 244 | >>> f.clean('P-3900800-H') |
| 245 | 'P3900800H' |
| 246 | >>> f.clean('P 39008008') |
| 247 | 'P39008008' |
| 248 | >>> f.clean('C-28795565') |
| 249 | 'C28795565' |
| 250 | >>> f.clean('C 2879556E') |
| 251 | 'C2879556E' |
| 252 | >>> f.clean('C28795567') |
| 253 | Traceback (most recent call last): |
| 254 | ... |
| 255 | ValidationError: [u'Invalid checksum for CIF.'] |
| 256 | >>> f.clean('I38790911') |
| 257 | Traceback (most recent call last): |
| 258 | ... |
| 259 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 260 | >>> f.clean('78699688-2') |
| 261 | Traceback (most recent call last): |
| 262 | ... |
| 263 | ValidationError: [u'Please enter a valid NIF, NIE, or CIF.'] |
| 264 | >>> f.clean('') |
| 265 | u'' |
| 266 | |
| 267 | # ESCCCField ############################################################## |
| 268 | |
| 269 | ESCCCField validates that data is a spanish bank account number (codigo cuenta cliente). |
| 270 | |
| 271 | >>> from django.contrib.localflavor.es.forms import ESCCCField |
| 272 | >>> f = ESCCCField() |
| 273 | >>> f.clean('20770338793100254321') |
| 274 | '20770338793100254321' |
| 275 | >>> f.clean('2077 0338 79 3100254321') |
| 276 | '2077 0338 79 3100254321' |
| 277 | >>> f.clean('2077-0338-79-3100254321') |
| 278 | '2077-0338-79-3100254321' |
| 279 | >>> f.clean('2077.0338.79.3100254321') |
| 280 | Traceback (most recent call last): |
| 281 | ... |
| 282 | ValidationError: [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'] |
| 283 | >>> f.clean('2077-0338-78-3100254321') |
| 284 | Traceback (most recent call last): |
| 285 | ... |
| 286 | ValidationError: [u'Invalid checksum for bank account number.'] |
| 287 | >>> f.clean('2077-0338-89-3100254321') |
| 288 | Traceback (most recent call last): |
| 289 | ... |
| 290 | ValidationError: [u'Invalid checksum for bank account number.'] |
| 291 | >>> f.clean('2077-03-3879-3100254321') |
| 292 | Traceback (most recent call last): |
| 293 | ... |
| 294 | ValidationError: [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'] |
| 295 | >>> f.clean('') |
| 296 | Traceback (most recent call last): |
| 297 | ... |
| 298 | ValidationError: [u'This field is required.'] |
| 299 | |
| 300 | >>> f = ESCCCField(required=False) |
| 301 | >>> f.clean('20770338793100254321') |
| 302 | '20770338793100254321' |
| 303 | >>> f.clean('2077 0338 79 3100254321') |
| 304 | '2077 0338 79 3100254321' |
| 305 | >>> f.clean('2077-0338-79-3100254321') |
| 306 | '2077-0338-79-3100254321' |
| 307 | >>> f.clean('2077.0338.79.3100254321') |
| 308 | Traceback (most recent call last): |
| 309 | ... |
| 310 | ValidationError: [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'] |
| 311 | >>> f.clean('2077-0338-78-3100254321') |
| 312 | Traceback (most recent call last): |
| 313 | ... |
| 314 | ValidationError: [u'Invalid checksum for bank account number.'] |
| 315 | >>> f.clean('2077-0338-89-3100254321') |
| 316 | Traceback (most recent call last): |
| 317 | ... |
| 318 | ValidationError: [u'Invalid checksum for bank account number.'] |
| 319 | >>> f.clean('2077-03-3879-3100254321') |
| 320 | Traceback (most recent call last): |
| 321 | ... |
| 322 | ValidationError: [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.'] |
| 323 | >>> f.clean('') |
| 324 | u'' |
| 325 | |
| 326 | # ESRegionSelect ############################################################## |
| 327 | |
| 328 | ESRegionSelect is a Select widget that uses a list of Spain regions as its choices. |
| 329 | >>> from django.contrib.localflavor.es.forms import ESRegionSelect |
| 330 | >>> w = ESRegionSelect() |
| 331 | >>> w.render('regions', 'CT') |
| 332 | u'<select name="regions">\n<option value="AN">Andalusia</option>\n<option value="AR">Aragon</option>\n<option value="O">Principality of Asturias</option>\n<option value="IB">Balearic Islands</option>\n<option value="PV">Basque Country</option>\n<option value="CN">Canary Islands</option>\n<option value="S">Cantabria</option>\n<option value="CM">Castile-La Mancha</option>\n<option value="CL">Castile and Leon</option>\n<option value="CT" selected="selected">Catalonia</option>\n<option value="EX">Extremadura</option>\n<option value="GA">Galicia</option>\n<option value="LO">La Rioja</option>\n<option value="M">Madrid</option>\n<option value="MU">Region of Murcia</option>\n<option value="NA">Foral Community of Navarre</option>\n<option value="VC">Valencian Community</option>\n</select>' |
| 333 | |
| 334 | # ESProvincenSelect ############################################################## |
| 335 | |
| 336 | ESProvinceSelect is a Select widget that uses a list of Spain provinces as its choices. |
| 337 | >>> from django.contrib.localflavor.es.forms import ESProvinceSelect |
| 338 | >>> w = ESProvinceSelect() |
| 339 | >>> w.render('provinces', '08') |
| 340 | u'<select name="provinces">\n<option value="01">Arava</option>\n<option value="02">Albacete</option>\n<option value="03">Alacant</option>\n<option value="04">Almeria</option>\n<option value="05">Avila</option>\n<option value="06">Badajoz</option>\n<option value="07">Illes Balears</option>\n<option value="08" selected="selected">Barcelona</option>\n<option value="09">Burgos</option>\n<option value="10">Caceres</option>\n<option value="11">Cadiz</option>\n<option value="12">Castello</option>\n<option value="13">Ciudad Real</option>\n<option value="14">Cordoba</option>\n<option value="15">A Coruna</option>\n<option value="16">Cuenca</option>\n<option value="17">Girona</option>\n<option value="18">Granada</option>\n<option value="19">Guadalajara</option>\n<option value="20">Guipuzkoa</option>\n<option value="21">Huelva</option>\n<option value="22">Huesca</option>\n<option value="23">Jaen</option>\n<option value="24">Leon</option>\n<option value="25">Lleida</option>\n<option value="26">La Rioja</option>\n<option value="27">Lugo</option>\n<option value="28">Madrid</option>\n<option value="29">Malaga</option>\n<option value="30">Murcia</option>\n<option value="31">Navarre</option>\n<option value="32">Ourense</option>\n<option value="33">Asturias</option>\n<option value="34">Palencia</option>\n<option value="35">Las Palmas</option>\n<option value="36">Pontevedra</option>\n<option value="37">Salamanca</option>\n<option value="38">Santa Cruz de Tenerife</option>\n<option value="39">Cantabria</option>\n<option value="40">Segovia</option>\n<option value="41">Seville</option>\n<option value="42">Soria</option>\n<option value="43">Tarragona</option>\n<option value="44">Teruel</option>\n<option value="45">Toledo</option>\n<option value="46">Valencia</option>\n<option value="47">Valladolid</option>\n<option value="48">Bizkaia</option>\n<option value="49">Zamora</option>\n<option value="50">Zaragoza</option>\n<option value="51">Ceuta</option>\n<option value="52">Melilla</option>\n</select>' |
| 341 | |
| 342 | """ |
| 343 | |