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