PageRenderTime 169ms CodeModel.GetById 24ms RepoModel.GetById 0ms 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 | 2 complexity | dd214679da5529954dec49dce77c83d3 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.localflavor.us.forms import (USZipCodeField,
  2. USPhoneNumberField, USStateField, USStateSelect, USSocialSecurityNumberField)
  3. from utils import LocalFlavorTestCase
  4. class USLocalFlavorTests(LocalFlavorTestCase):
  5. def test_USStateSelect(self):
  6. f = USStateSelect()
  7. out = u'''<select name="state">
  8. <option value="AL">Alabama</option>
  9. <option value="AK">Alaska</option>
  10. <option value="AS">American Samoa</option>
  11. <option value="AZ">Arizona</option>
  12. <option value="AR">Arkansas</option>
  13. <option value="AA">Armed Forces Americas</option>
  14. <option value="AE">Armed Forces Europe</option>
  15. <option value="AP">Armed Forces Pacific</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.assertEqual(f.render('state', 'IL'), out)
  69. def test_USZipCodeField(self):
  70. error_format = [u'Enter a zip code in the format XXXXX or XXXXX-XXXX.']
  71. valid = {
  72. '60606': '60606',
  73. 60606: '60606',
  74. '04000': '04000',
  75. '60606-1234': '60606-1234',
  76. }
  77. invalid = {
  78. '4000': error_format,
  79. '6060-1234': error_format,
  80. '60606-': error_format,
  81. }
  82. self.assertFieldOutput(USZipCodeField, valid, invalid)
  83. def test_USPhoneNumberField(self):
  84. error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
  85. valid = {
  86. '312-555-1212': '312-555-1212',
  87. '3125551212': '312-555-1212',
  88. '312 555-1212': '312-555-1212',
  89. '(312) 555-1212': '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. }
  95. invalid = {
  96. '555-1212': error_format,
  97. '312-55-1212': error_format,
  98. }
  99. self.assertFieldOutput(USPhoneNumberField, valid, invalid)
  100. def test_USStateField(self):
  101. error_invalid = [u'Enter a U.S. state or territory.']
  102. valid = {
  103. 'il': 'IL',
  104. 'IL': 'IL',
  105. 'illinois': 'IL',
  106. ' illinois ': 'IL',
  107. }
  108. invalid = {
  109. 60606: error_invalid,
  110. }
  111. self.assertFieldOutput(USStateField, valid, invalid)
  112. def test_USSocialSecurityNumberField(self):
  113. error_invalid = [u'Enter a valid U.S. Social Security number in XXX-XX-XXXX format.']
  114. valid = {
  115. '987-65-4330': '987-65-4330',
  116. '987654330': '987-65-4330',
  117. }
  118. invalid = {
  119. '078-05-1120': error_invalid,
  120. }
  121. self.assertFieldOutput(USSocialSecurityNumberField, valid, invalid)