PageRenderTime 83ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 33ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/us.py

https://code.google.com/p/mango-py/
Python | 129 lines | 126 code | 3 blank | 0 comment | 5 complexity | dd214679da5529954dec49dce77c83d3 MD5 | raw file
  1from django.contrib.localflavor.us.forms import (USZipCodeField,
  2    USPhoneNumberField, USStateField, USStateSelect, USSocialSecurityNumberField)
  3
  4from utils import LocalFlavorTestCase
  5
  6
  7class USLocalFlavorTests(LocalFlavorTestCase):
  8    def test_USStateSelect(self):
  9        f = USStateSelect()
 10        out = u'''<select name="state">
 11<option value="AL">Alabama</option>
 12<option value="AK">Alaska</option>
 13<option value="AS">American Samoa</option>
 14<option value="AZ">Arizona</option>
 15<option value="AR">Arkansas</option>
 16<option value="AA">Armed Forces Americas</option>
 17<option value="AE">Armed Forces Europe</option>
 18<option value="AP">Armed Forces Pacific</option>
 19<option value="CA">California</option>
 20<option value="CO">Colorado</option>
 21<option value="CT">Connecticut</option>
 22<option value="DE">Delaware</option>
 23<option value="DC">District of Columbia</option>
 24<option value="FL">Florida</option>
 25<option value="GA">Georgia</option>
 26<option value="GU">Guam</option>
 27<option value="HI">Hawaii</option>
 28<option value="ID">Idaho</option>
 29<option value="IL" selected="selected">Illinois</option>
 30<option value="IN">Indiana</option>
 31<option value="IA">Iowa</option>
 32<option value="KS">Kansas</option>
 33<option value="KY">Kentucky</option>
 34<option value="LA">Louisiana</option>
 35<option value="ME">Maine</option>
 36<option value="MD">Maryland</option>
 37<option value="MA">Massachusetts</option>
 38<option value="MI">Michigan</option>
 39<option value="MN">Minnesota</option>
 40<option value="MS">Mississippi</option>
 41<option value="MO">Missouri</option>
 42<option value="MT">Montana</option>
 43<option value="NE">Nebraska</option>
 44<option value="NV">Nevada</option>
 45<option value="NH">New Hampshire</option>
 46<option value="NJ">New Jersey</option>
 47<option value="NM">New Mexico</option>
 48<option value="NY">New York</option>
 49<option value="NC">North Carolina</option>
 50<option value="ND">North Dakota</option>
 51<option value="MP">Northern Mariana Islands</option>
 52<option value="OH">Ohio</option>
 53<option value="OK">Oklahoma</option>
 54<option value="OR">Oregon</option>
 55<option value="PA">Pennsylvania</option>
 56<option value="PR">Puerto Rico</option>
 57<option value="RI">Rhode Island</option>
 58<option value="SC">South Carolina</option>
 59<option value="SD">South Dakota</option>
 60<option value="TN">Tennessee</option>
 61<option value="TX">Texas</option>
 62<option value="UT">Utah</option>
 63<option value="VT">Vermont</option>
 64<option value="VI">Virgin Islands</option>
 65<option value="VA">Virginia</option>
 66<option value="WA">Washington</option>
 67<option value="WV">West Virginia</option>
 68<option value="WI">Wisconsin</option>
 69<option value="WY">Wyoming</option>
 70</select>'''
 71        self.assertEqual(f.render('state', 'IL'), out)
 72
 73    def test_USZipCodeField(self):
 74        error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.']
 75        valid = {
 76            '60606': '60606',
 77            60606: '60606',
 78            '04000': '04000',
 79            '60606-1234': '60606-1234',
 80        }
 81        invalid = {
 82            '4000': error_format,
 83            '6060-1234': error_format,
 84            '60606-': error_format,
 85        }
 86        self.assertFieldOutput(USZipCodeField, valid, invalid)
 87
 88    def test_USPhoneNumberField(self):
 89        error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
 90        valid = {
 91            '312-555-1212': '312-555-1212',
 92            '3125551212': '312-555-1212',
 93            '312 555-1212': '312-555-1212',
 94            '(312) 555-1212': '312-555-1212',
 95            '312 555 1212': '312-555-1212',
 96            '312.555.1212': '312-555-1212',
 97            '312.555-1212': '312-555-1212',
 98            ' (312) 555.1212 ': '312-555-1212',
 99        }
100        invalid = {
101            '555-1212': error_format,
102            '312-55-1212': error_format,
103        }
104        self.assertFieldOutput(USPhoneNumberField, valid, invalid)
105
106    def test_USStateField(self):
107        error_invalid = [u'Enter a U.S. state or territory.']
108        valid = {
109            'il': 'IL',
110            'IL': 'IL',
111            'illinois': 'IL',
112            '  illinois ': 'IL',
113        }
114        invalid = {
115            60606: error_invalid,
116        }
117        self.assertFieldOutput(USStateField, valid, invalid)
118
119    def test_USSocialSecurityNumberField(self):
120        error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
121
122        valid = {
123            '987-65-4330': '987-65-4330',
124            '987654330': '987-65-4330',
125        }
126        invalid = {
127            '078-05-1120': error_invalid,
128        }
129        self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)