| 1 | from django.test import TestCase |
| 2 | from models import Place |
| 3 | from forms import PlaceForm |
| 4 | |
| 5 | class USLocalflavorTests(TestCase): |
| 6 | def setUp(self): |
| 7 | self.form = PlaceForm({'state':'GA', 'state_req':'NC', 'name':'impossible'}) |
| 8 | |
| 9 | def test_get_display_methods(self): |
| 10 | """Test that the get_*_display() methods are added to the model instances.""" |
| 11 | place = self.form.save() |
| 12 | self.assertEqual(place.get_state_display(), 'Georgia') |
| 13 | self.assertEqual(place.get_state_req_display(), 'North Carolina') |
| 14 | |
| 15 | def test_required(self): |
| 16 | """Test that required USStateFields throw appropriate errors.""" |
| 17 | form = PlaceForm({'state':'GA', 'name':'Place in GA'}) |
| 18 | self.assertFalse(form.is_valid()) |
| 19 | self.assertEqual(form.errors['state_req'], [u'This field is required.']) |
| 20 | |
| 21 | def test_field_blank_option(self): |
| 22 | """Test that the empty option is there.""" |
| 23 | state_select_html = """\ |
| 24 | <select name="state" id="id_state"> |
| 25 | <option value="">---------</option> |
| 26 | <option value="AL">Alabama</option> |
| 27 | <option value="AK">Alaska</option> |
| 28 | <option value="AS">American Samoa</option> |
| 29 | <option value="AZ">Arizona</option> |
| 30 | <option value="AR">Arkansas</option> |
| 31 | <option value="CA">California</option> |
| 32 | <option value="CO">Colorado</option> |
| 33 | <option value="CT">Connecticut</option> |
| 34 | <option value="DE">Delaware</option> |
| 35 | <option value="DC">District of Columbia</option> |
| 36 | <option value="FL">Florida</option> |
| 37 | <option value="GA" selected="selected">Georgia</option> |
| 38 | <option value="GU">Guam</option> |
| 39 | <option value="HI">Hawaii</option> |
| 40 | <option value="ID">Idaho</option> |
| 41 | <option value="IL">Illinois</option> |
| 42 | <option value="IN">Indiana</option> |
| 43 | <option value="IA">Iowa</option> |
| 44 | <option value="KS">Kansas</option> |
| 45 | <option value="KY">Kentucky</option> |
| 46 | <option value="LA">Louisiana</option> |
| 47 | <option value="ME">Maine</option> |
| 48 | <option value="MD">Maryland</option> |
| 49 | <option value="MA">Massachusetts</option> |
| 50 | <option value="MI">Michigan</option> |
| 51 | <option value="MN">Minnesota</option> |
| 52 | <option value="MS">Mississippi</option> |
| 53 | <option value="MO">Missouri</option> |
| 54 | <option value="MT">Montana</option> |
| 55 | <option value="NE">Nebraska</option> |
| 56 | <option value="NV">Nevada</option> |
| 57 | <option value="NH">New Hampshire</option> |
| 58 | <option value="NJ">New Jersey</option> |
| 59 | <option value="NM">New Mexico</option> |
| 60 | <option value="NY">New York</option> |
| 61 | <option value="NC">North Carolina</option> |
| 62 | <option value="ND">North Dakota</option> |
| 63 | <option value="MP">Northern Mariana Islands</option> |
| 64 | <option value="OH">Ohio</option> |
| 65 | <option value="OK">Oklahoma</option> |
| 66 | <option value="OR">Oregon</option> |
| 67 | <option value="PA">Pennsylvania</option> |
| 68 | <option value="PR">Puerto Rico</option> |
| 69 | <option value="RI">Rhode Island</option> |
| 70 | <option value="SC">South Carolina</option> |
| 71 | <option value="SD">South Dakota</option> |
| 72 | <option value="TN">Tennessee</option> |
| 73 | <option value="TX">Texas</option> |
| 74 | <option value="UT">Utah</option> |
| 75 | <option value="VT">Vermont</option> |
| 76 | <option value="VI">Virgin Islands</option> |
| 77 | <option value="VA">Virginia</option> |
| 78 | <option value="WA">Washington</option> |
| 79 | <option value="WV">West Virginia</option> |
| 80 | <option value="WI">Wisconsin</option> |
| 81 | <option value="WY">Wyoming</option> |
| 82 | </select>""" |
| 83 | self.assertEqual(str(self.form['state']), state_select_html) |