PageRenderTime 911ms CodeModel.GetById 788ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

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

https://code.google.com/p/mango-py/
Python | 155 lines | 148 code | 4 blank | 3 comment | 0 complexity | c8205091458ece8f6dab5676928b808d MD5 | raw file
  1from django.test import TestCase
  2from forms import USPlaceForm
  3
  4class USLocalflavorTests(TestCase):
  5    def setUp(self):
  6        self.form = USPlaceForm({'state':'GA', 'state_req':'NC', 'postal_code': 'GA', 'name':'impossible'})
  7
  8    def test_get_display_methods(self):
  9        """Test that the get_*_display() methods are added to the model instances."""
 10        place = self.form.save()
 11        self.assertEqual(place.get_state_display(), 'Georgia')
 12        self.assertEqual(place.get_state_req_display(), 'North Carolina')
 13
 14    def test_required(self):
 15        """Test that required USStateFields throw appropriate errors."""
 16        form = USPlaceForm({'state':'GA', 'name':'Place in GA'})
 17        self.assertFalse(form.is_valid())
 18        self.assertEqual(form.errors['state_req'], [u'This field is required.'])
 19
 20    def test_field_blank_option(self):
 21        """Test that the empty option is there."""
 22        state_select_html = """\
 23<select name="state" id="id_state">
 24<option value="">---------</option>
 25<option value="AL">Alabama</option>
 26<option value="AK">Alaska</option>
 27<option value="AS">American Samoa</option>
 28<option value="AZ">Arizona</option>
 29<option value="AR">Arkansas</option>
 30<option value="AA">Armed Forces Americas</option>
 31<option value="AE">Armed Forces Europe</option>
 32<option value="AP">Armed Forces Pacific</option>
 33<option value="CA">California</option>
 34<option value="CO">Colorado</option>
 35<option value="CT">Connecticut</option>
 36<option value="DE">Delaware</option>
 37<option value="DC">District of Columbia</option>
 38<option value="FL">Florida</option>
 39<option value="GA" selected="selected">Georgia</option>
 40<option value="GU">Guam</option>
 41<option value="HI">Hawaii</option>
 42<option value="ID">Idaho</option>
 43<option value="IL">Illinois</option>
 44<option value="IN">Indiana</option>
 45<option value="IA">Iowa</option>
 46<option value="KS">Kansas</option>
 47<option value="KY">Kentucky</option>
 48<option value="LA">Louisiana</option>
 49<option value="ME">Maine</option>
 50<option value="MD">Maryland</option>
 51<option value="MA">Massachusetts</option>
 52<option value="MI">Michigan</option>
 53<option value="MN">Minnesota</option>
 54<option value="MS">Mississippi</option>
 55<option value="MO">Missouri</option>
 56<option value="MT">Montana</option>
 57<option value="NE">Nebraska</option>
 58<option value="NV">Nevada</option>
 59<option value="NH">New Hampshire</option>
 60<option value="NJ">New Jersey</option>
 61<option value="NM">New Mexico</option>
 62<option value="NY">New York</option>
 63<option value="NC">North Carolina</option>
 64<option value="ND">North Dakota</option>
 65<option value="MP">Northern Mariana Islands</option>
 66<option value="OH">Ohio</option>
 67<option value="OK">Oklahoma</option>
 68<option value="OR">Oregon</option>
 69<option value="PA">Pennsylvania</option>
 70<option value="PR">Puerto Rico</option>
 71<option value="RI">Rhode Island</option>
 72<option value="SC">South Carolina</option>
 73<option value="SD">South Dakota</option>
 74<option value="TN">Tennessee</option>
 75<option value="TX">Texas</option>
 76<option value="UT">Utah</option>
 77<option value="VT">Vermont</option>
 78<option value="VI">Virgin Islands</option>
 79<option value="VA">Virginia</option>
 80<option value="WA">Washington</option>
 81<option value="WV">West Virginia</option>
 82<option value="WI">Wisconsin</option>
 83<option value="WY">Wyoming</option>
 84</select>"""
 85        self.assertEqual(str(self.form['state']), state_select_html)
 86
 87    def test_full_postal_code_list(self):
 88        """Test that the full USPS code field is really the full list."""
 89        usps_select_html = """\
 90<select name="postal_code" id="id_postal_code">
 91<option value="">---------</option>
 92<option value="AL">Alabama</option>
 93<option value="AK">Alaska</option>
 94<option value="AS">American Samoa</option>
 95<option value="AZ">Arizona</option>
 96<option value="AR">Arkansas</option>
 97<option value="AA">Armed Forces Americas</option>
 98<option value="AE">Armed Forces Europe</option>
 99<option value="AP">Armed Forces Pacific</option>
100<option value="CA">California</option>
101<option value="CO">Colorado</option>
102<option value="CT">Connecticut</option>
103<option value="DE">Delaware</option>
104<option value="DC">District of Columbia</option>
105<option value="FM">Federated States of Micronesia</option>
106<option value="FL">Florida</option>
107<option value="GA" selected="selected">Georgia</option>
108<option value="GU">Guam</option>
109<option value="HI">Hawaii</option>
110<option value="ID">Idaho</option>
111<option value="IL">Illinois</option>
112<option value="IN">Indiana</option>
113<option value="IA">Iowa</option>
114<option value="KS">Kansas</option>
115<option value="KY">Kentucky</option>
116<option value="LA">Louisiana</option>
117<option value="ME">Maine</option>
118<option value="MH">Marshall Islands</option>
119<option value="MD">Maryland</option>
120<option value="MA">Massachusetts</option>
121<option value="MI">Michigan</option>
122<option value="MN">Minnesota</option>
123<option value="MS">Mississippi</option>
124<option value="MO">Missouri</option>
125<option value="MT">Montana</option>
126<option value="NE">Nebraska</option>
127<option value="NV">Nevada</option>
128<option value="NH">New Hampshire</option>
129<option value="NJ">New Jersey</option>
130<option value="NM">New Mexico</option>
131<option value="NY">New York</option>
132<option value="NC">North Carolina</option>
133<option value="ND">North Dakota</option>
134<option value="MP">Northern Mariana Islands</option>
135<option value="OH">Ohio</option>
136<option value="OK">Oklahoma</option>
137<option value="OR">Oregon</option>
138<option value="PW">Palau</option>
139<option value="PA">Pennsylvania</option>
140<option value="PR">Puerto Rico</option>
141<option value="RI">Rhode Island</option>
142<option value="SC">South Carolina</option>
143<option value="SD">South Dakota</option>
144<option value="TN">Tennessee</option>
145<option value="TX">Texas</option>
146<option value="UT">Utah</option>
147<option value="VT">Vermont</option>
148<option value="VI">Virgin Islands</option>
149<option value="VA">Virginia</option>
150<option value="WA">Washington</option>
151<option value="WV">West Virginia</option>
152<option value="WI">Wisconsin</option>
153<option value="WY">Wyoming</option>
154</select>"""
155        self.assertEqual(str(self.form['postal_code']), usps_select_html)