PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/es.py

https://code.google.com/p/mango-py/
Python | 172 lines | 169 code | 3 blank | 0 comment | 7 complexity | 935500b24672e78bec984b975603438f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.localflavor.es.forms import (ESPostalCodeField, ESPhoneNumberField,
  2. ESIdentityCardNumberField, ESCCCField, ESRegionSelect, ESProvinceSelect)
  3. from utils import LocalFlavorTestCase
  4. class ESLocalFlavorTests(LocalFlavorTestCase):
  5. def test_ESRegionSelect(self):
  6. f = ESRegionSelect()
  7. out = u'''<select name="regions">
  8. <option value="AN">Andalusia</option>
  9. <option value="AR">Aragon</option>
  10. <option value="O">Principality of Asturias</option>
  11. <option value="IB">Balearic Islands</option>
  12. <option value="PV">Basque Country</option>
  13. <option value="CN">Canary Islands</option>
  14. <option value="S">Cantabria</option>
  15. <option value="CM">Castile-La Mancha</option>
  16. <option value="CL">Castile and Leon</option>
  17. <option value="CT" selected="selected">Catalonia</option>
  18. <option value="EX">Extremadura</option>
  19. <option value="GA">Galicia</option>
  20. <option value="LO">La Rioja</option>
  21. <option value="M">Madrid</option>
  22. <option value="MU">Region of Murcia</option>
  23. <option value="NA">Foral Community of Navarre</option>
  24. <option value="VC">Valencian Community</option>
  25. </select>'''
  26. self.assertEqual(f.render('regions', 'CT'), out)
  27. def test_ESProvinceSelect(self):
  28. f = ESProvinceSelect()
  29. out = u'''<select name="provinces">
  30. <option value="01">Arava</option>
  31. <option value="02">Albacete</option>
  32. <option value="03">Alacant</option>
  33. <option value="04">Almeria</option>
  34. <option value="05">Avila</option>
  35. <option value="06">Badajoz</option>
  36. <option value="07">Illes Balears</option>
  37. <option value="08" selected="selected">Barcelona</option>
  38. <option value="09">Burgos</option>
  39. <option value="10">Caceres</option>
  40. <option value="11">Cadiz</option>
  41. <option value="12">Castello</option>
  42. <option value="13">Ciudad Real</option>
  43. <option value="14">Cordoba</option>
  44. <option value="15">A Coruna</option>
  45. <option value="16">Cuenca</option>
  46. <option value="17">Girona</option>
  47. <option value="18">Granada</option>
  48. <option value="19">Guadalajara</option>
  49. <option value="20">Guipuzkoa</option>
  50. <option value="21">Huelva</option>
  51. <option value="22">Huesca</option>
  52. <option value="23">Jaen</option>
  53. <option value="24">Leon</option>
  54. <option value="25">Lleida</option>
  55. <option value="26">La Rioja</option>
  56. <option value="27">Lugo</option>
  57. <option value="28">Madrid</option>
  58. <option value="29">Malaga</option>
  59. <option value="30">Murcia</option>
  60. <option value="31">Navarre</option>
  61. <option value="32">Ourense</option>
  62. <option value="33">Asturias</option>
  63. <option value="34">Palencia</option>
  64. <option value="35">Las Palmas</option>
  65. <option value="36">Pontevedra</option>
  66. <option value="37">Salamanca</option>
  67. <option value="38">Santa Cruz de Tenerife</option>
  68. <option value="39">Cantabria</option>
  69. <option value="40">Segovia</option>
  70. <option value="41">Seville</option>
  71. <option value="42">Soria</option>
  72. <option value="43">Tarragona</option>
  73. <option value="44">Teruel</option>
  74. <option value="45">Toledo</option>
  75. <option value="46">Valencia</option>
  76. <option value="47">Valladolid</option>
  77. <option value="48">Bizkaia</option>
  78. <option value="49">Zamora</option>
  79. <option value="50">Zaragoza</option>
  80. <option value="51">Ceuta</option>
  81. <option value="52">Melilla</option>
  82. </select>'''
  83. self.assertEqual(f.render('provinces', '08'), out)
  84. def test_ESPostalCodeField(self):
  85. error_invalid = [u'Enter a valid postal code in the range and format 01XXX - 52XXX.']
  86. valid = {
  87. '08028': '08028',
  88. '28080': '28080',
  89. }
  90. invalid = {
  91. '53001': error_invalid,
  92. '0801': error_invalid,
  93. '080001': error_invalid,
  94. '00999': error_invalid,
  95. '08 01': error_invalid,
  96. '08A01': error_invalid,
  97. }
  98. self.assertFieldOutput(ESPostalCodeField, valid, invalid)
  99. def test_ESPhoneNumberField(self):
  100. error_invalid = [u'Enter a valid phone number in one of the formats 6XXXXXXXX, 8XXXXXXXX or 9XXXXXXXX.']
  101. valid = {
  102. '650010101': '650010101',
  103. '931234567': '931234567',
  104. '800123123': '800123123',
  105. }
  106. invalid = {
  107. '555555555': error_invalid,
  108. '789789789': error_invalid,
  109. '99123123': error_invalid,
  110. '9999123123': error_invalid,
  111. }
  112. self.assertFieldOutput(ESPhoneNumberField, valid, invalid)
  113. def test_ESIdentityCardNumberField(self):
  114. error_invalid = [u'Please enter a valid NIF, NIE, or CIF.']
  115. error_checksum_nif = [u'Invalid checksum for NIF.']
  116. error_checksum_nie = [u'Invalid checksum for NIE.']
  117. error_checksum_cif = [u'Invalid checksum for CIF.']
  118. valid = {
  119. '78699688J': '78699688J',
  120. '78699688-J': '78699688J',
  121. '78699688 J': '78699688J',
  122. '78699688 j': '78699688J',
  123. 'X0901797J': 'X0901797J',
  124. 'X-6124387-Q': 'X6124387Q',
  125. 'X 0012953 G': 'X0012953G',
  126. 'x-3287690-r': 'X3287690R',
  127. 't-03287690r': 'T03287690R',
  128. 'P2907500I': 'P2907500I',
  129. 'B38790911': 'B38790911',
  130. 'B31234560': 'B31234560',
  131. 'B-3879091A': 'B3879091A',
  132. 'B 38790911': 'B38790911',
  133. 'P-3900800-H': 'P3900800H',
  134. 'P 39008008': 'P39008008',
  135. 'C-28795565': 'C28795565',
  136. 'C 2879556E': 'C2879556E',
  137. }
  138. invalid = {
  139. '78699688T': error_checksum_nif,
  140. 'X-03287690': error_invalid,
  141. 'X-03287690-T': error_checksum_nie,
  142. 'B 38790917': error_checksum_cif,
  143. 'C28795567': error_checksum_cif,
  144. 'I38790911': error_invalid,
  145. '78699688-2': error_invalid,
  146. }
  147. self.assertFieldOutput(ESIdentityCardNumberField, valid, invalid)
  148. def test_ESCCCField(self):
  149. error_invalid = [u'Please enter a valid bank account number in format XXXX-XXXX-XX-XXXXXXXXXX.']
  150. error_checksum = [u'Invalid checksum for bank account number.']
  151. valid = {
  152. '20770338793100254321': '20770338793100254321',
  153. '2077 0338 79 3100254321': '2077 0338 79 3100254321',
  154. '2077-0338-79-3100254321': '2077-0338-79-3100254321',
  155. }
  156. invalid = {
  157. '2077.0338.79.3100254321': error_invalid,
  158. '2077-0338-78-3100254321': error_checksum,
  159. '2077-0338-89-3100254321': error_checksum,
  160. '2077-03-3879-3100254321': error_invalid,
  161. }
  162. self.assertFieldOutput(ESCCCField, valid, invalid)