from django.contrib.localflavor.us.forms import (USZipCodeField, USPhoneNumberField, USStateField, USStateSelect, USSocialSecurityNumberField) from utils import LocalFlavorTestCase class USLocalFlavorTests(LocalFlavorTestCase): def test_USStateSelect(self): f = USStateSelect() out = u'''''' self.assertEquals(f.render('state', 'IL'), out) def test_USZipCodeField(self): error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.'] valid = { '60606': '60606', 60606: '60606', '04000': '04000', '60606-1234': '60606-1234', } invalid = { '4000': error_format, '6060-1234': error_format, '60606-': error_format, } self.assertFieldOutput(USZipCodeField, valid, invalid) def test_USPhoneNumberField(self): error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.'] valid = { '312-555-1212': '312-555-1212', '3125551212': '312-555-1212', '312 555-1212': '312-555-1212', '(312) 555-1212': '312-555-1212', '312 555 1212': '312-555-1212', '312.555.1212': '312-555-1212', '312.555-1212': '312-555-1212', ' (312) 555.1212 ': '312-555-1212', } invalid = { '555-1212': error_format, '312-55-1212': error_format, } self.assertFieldOutput(USPhoneNumberField, valid, invalid) def test_USStateField(self): error_invalid = [u'Enter a U.S. state or territory.'] valid = { 'il': 'IL', 'IL': 'IL', 'illinois': 'IL', ' illinois ': 'IL', } invalid = { 60606: error_invalid, } self.assertFieldOutput(USStateField, valid, invalid) def test_USSocialSecurityNumberField(self): error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.'] valid = { '987-65-4330': '987-65-4330', '987654330': '987-65-4330', } invalid = { '078-05-1120': error_invalid, } self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)