from django.contrib.localflavor.es.forms import (ESPostalCodeField, ESPhoneNumberField,
ESIdentityCardNumberField, ESCCCField, ESRegionSelect, ESProvinceSelect)
from utils import LocalFlavorTestCase
class ESLocalFlavorTests(LocalFlavorTestCase):
def test_ESRegionSelect(self):
f = ESRegionSelect()
out = u''''''
self.assertEqual(f.render('regions', 'CT'), out)
def test_ESProvinceSelect(self):
f = ESProvinceSelect()
out = u''''''
self.assertEqual(f.render('provinces', '08'), out)
def test_ESPostalCodeField(self):
error_invalid = [u'Enter a valid postal code in the range and format 01XXX - 52XXX.']
valid = {
'08028': '08028',
'28080': '28080',
}
invalid = {
'53001': error_invalid,
'0801': error_invalid,
'080001': error_invalid,
'00999': error_invalid,
'08 01': error_invalid,
'08A01': error_invalid,
}
self.assertFieldOutput(ESPostalCodeField, valid, invalid)
def test_ESPhoneNumberField(self):
error_invalid = [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.']
valid = {
'650010101': '650010101',
'931234567': '931234567',
'800123123': '800123123',
}
invalid = {
'555555555': error_invalid,
'789789789': error_invalid,
'99123123': error_invalid,
'9999123123': error_invalid,
}
self.assertFieldOutput(ESPhoneNumberField, valid, invalid)
def test_ESIdentityCardNumberField(self):
error_invalid = [u'Please enter a valid NIF, NIE, or CIF.']
error_checksum_nif = [u'Invalid checksum for NIF.']
error_checksum_nie = [u'Invalid checksum for NIE.']
error_checksum_cif = [u'Invalid checksum for CIF.']
valid = {
'78699688J': '78699688J',
'78699688-J': '78699688J',
'78699688 J': '78699688J',
'78699688 j': '78699688J',
'X0901797J': 'X0901797J',
'X-6124387-Q': 'X6124387Q',
'X 0012953 G': 'X0012953G',
'x-3287690-r': 'X3287690R',
't-03287690r': 'T03287690R',
'P2907500I': 'P2907500I',
'B38790911': 'B38790911',
'B31234560': 'B31234560',
'B-3879091A': 'B3879091A',
'B 38790911': 'B38790911',
'P-3900800-H': 'P3900800H',
'P 39008008': 'P39008008',
'C-28795565': 'C28795565',
'C 2879556E': 'C2879556E',
}
invalid = {
'78699688T': error_checksum_nif,
'X-03287690': error_invalid,
'X-03287690-T': error_checksum_nie,
'B 38790917': error_checksum_cif,
'C28795567': error_checksum_cif,
'I38790911': error_invalid,
'78699688-2': error_invalid,
}
self.assertFieldOutput(ESIdentityCardNumberField, valid, invalid)
def test_ESCCCField(self):
error_invalid = [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.']
error_checksum = [u'Invalid checksum for bank account number.']
valid = {
'20770338793100254321': '20770338793100254321',
'2077 0338 79 3100254321': '2077 0338 79 3100254321',
'2077-0338-79-3100254321': '2077-0338-79-3100254321',
}
invalid = {
'2077.0338.79.3100254321': error_invalid,
'2077-0338-78-3100254321': error_checksum,
'2077-0338-89-3100254321': error_checksum,
'2077-03-3879-3100254321': error_invalid,
}
self.assertFieldOutput(ESCCCField, valid, invalid)