PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/id.py

https://code.google.com/p/mango-py/
Python | 194 lines | 188 code | 6 blank | 0 comment | 0 complexity | 65c6e0b0a083fa8d55019a9757f01b82 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import warnings
  2. from django.contrib.localflavor.id.forms import (IDPhoneNumberField,
  3. IDPostCodeField, IDNationalIdentityNumberField, IDLicensePlateField,
  4. IDProvinceSelect, IDLicensePlatePrefixSelect)
  5. from utils import LocalFlavorTestCase
  6. class IDLocalFlavorTests(LocalFlavorTestCase):
  7. def setUp(self):
  8. self.save_warnings_state()
  9. warnings.filterwarnings(
  10. "ignore",
  11. category=RuntimeWarning,
  12. module='django.contrib.localflavor.id.id_choices'
  13. )
  14. def tearDown(self):
  15. self.restore_warnings_state()
  16. def test_IDProvinceSelect(self):
  17. f = IDProvinceSelect()
  18. out = u'''<select name="provinces">
  19. <option value="ACE">Aceh</option>
  20. <option value="BLI">Bali</option>
  21. <option value="BTN">Banten</option>
  22. <option value="BKL">Bengkulu</option>
  23. <option value="DIY">Yogyakarta</option>
  24. <option value="JKT">Jakarta</option>
  25. <option value="GOR">Gorontalo</option>
  26. <option value="JMB">Jambi</option>
  27. <option value="JBR">Jawa Barat</option>
  28. <option value="JTG">Jawa Tengah</option>
  29. <option value="JTM">Jawa Timur</option>
  30. <option value="KBR">Kalimantan Barat</option>
  31. <option value="KSL">Kalimantan Selatan</option>
  32. <option value="KTG">Kalimantan Tengah</option>
  33. <option value="KTM">Kalimantan Timur</option>
  34. <option value="BBL">Kepulauan Bangka-Belitung</option>
  35. <option value="KRI">Kepulauan Riau</option>
  36. <option value="LPG" selected="selected">Lampung</option>
  37. <option value="MLK">Maluku</option>
  38. <option value="MUT">Maluku Utara</option>
  39. <option value="NTB">Nusa Tenggara Barat</option>
  40. <option value="NTT">Nusa Tenggara Timur</option>
  41. <option value="PPA">Papua</option>
  42. <option value="PPB">Papua Barat</option>
  43. <option value="RIU">Riau</option>
  44. <option value="SLB">Sulawesi Barat</option>
  45. <option value="SLS">Sulawesi Selatan</option>
  46. <option value="SLT">Sulawesi Tengah</option>
  47. <option value="SLR">Sulawesi Tenggara</option>
  48. <option value="SLU">Sulawesi Utara</option>
  49. <option value="SMB">Sumatera Barat</option>
  50. <option value="SMS">Sumatera Selatan</option>
  51. <option value="SMU">Sumatera Utara</option>
  52. </select>'''
  53. self.assertEqual(f.render('provinces', 'LPG'), out)
  54. def test_IDLicensePlatePrefixSelect(self):
  55. f = IDLicensePlatePrefixSelect()
  56. out = u'''<select name="codes">
  57. <option value="A">Banten</option>
  58. <option value="AA">Magelang</option>
  59. <option value="AB">Yogyakarta</option>
  60. <option value="AD">Surakarta - Solo</option>
  61. <option value="AE">Madiun</option>
  62. <option value="AG">Kediri</option>
  63. <option value="B">Jakarta</option>
  64. <option value="BA">Sumatera Barat</option>
  65. <option value="BB">Tapanuli</option>
  66. <option value="BD">Bengkulu</option>
  67. <option value="BE" selected="selected">Lampung</option>
  68. <option value="BG">Sumatera Selatan</option>
  69. <option value="BH">Jambi</option>
  70. <option value="BK">Sumatera Utara</option>
  71. <option value="BL">Nanggroe Aceh Darussalam</option>
  72. <option value="BM">Riau</option>
  73. <option value="BN">Kepulauan Bangka Belitung</option>
  74. <option value="BP">Kepulauan Riau</option>
  75. <option value="CC">Corps Consulate</option>
  76. <option value="CD">Corps Diplomatic</option>
  77. <option value="D">Bandung</option>
  78. <option value="DA">Kalimantan Selatan</option>
  79. <option value="DB">Sulawesi Utara Daratan</option>
  80. <option value="DC">Sulawesi Barat</option>
  81. <option value="DD">Sulawesi Selatan</option>
  82. <option value="DE">Maluku</option>
  83. <option value="DG">Maluku Utara</option>
  84. <option value="DH">NTT - Timor</option>
  85. <option value="DK">Bali</option>
  86. <option value="DL">Sulawesi Utara Kepulauan</option>
  87. <option value="DM">Gorontalo</option>
  88. <option value="DN">Sulawesi Tengah</option>
  89. <option value="DR">NTB - Lombok</option>
  90. <option value="DS">Papua dan Papua Barat</option>
  91. <option value="DT">Sulawesi Tenggara</option>
  92. <option value="E">Cirebon</option>
  93. <option value="EA">NTB - Sumbawa</option>
  94. <option value="EB">NTT - Flores</option>
  95. <option value="ED">NTT - Sumba</option>
  96. <option value="F">Bogor</option>
  97. <option value="G">Pekalongan</option>
  98. <option value="H">Semarang</option>
  99. <option value="K">Pati</option>
  100. <option value="KB">Kalimantan Barat</option>
  101. <option value="KH">Kalimantan Tengah</option>
  102. <option value="KT">Kalimantan Timur</option>
  103. <option value="L">Surabaya</option>
  104. <option value="M">Madura</option>
  105. <option value="N">Malang</option>
  106. <option value="P">Jember</option>
  107. <option value="R">Banyumas</option>
  108. <option value="RI">Federal Government</option>
  109. <option value="S">Bojonegoro</option>
  110. <option value="T">Purwakarta</option>
  111. <option value="W">Sidoarjo</option>
  112. <option value="Z">Garut</option>
  113. </select>'''
  114. self.assertEqual(f.render('codes', 'BE'), out)
  115. def test_IDPhoneNumberField(self):
  116. error_invalid = [u'Enter a valid phone number']
  117. valid = {
  118. '0812-3456789': u'0812-3456789',
  119. '081234567890': u'081234567890',
  120. '021 345 6789': u'021 345 6789',
  121. '0213456789': u'0213456789',
  122. '+62-21-3456789': u'+62-21-3456789',
  123. '(021) 345 6789': u'(021) 345 6789',
  124. }
  125. invalid = {
  126. '0123456789': error_invalid,
  127. '+62-021-3456789': error_invalid,
  128. '+62-021-3456789': error_invalid,
  129. '+62-0812-3456789': error_invalid,
  130. '0812345678901': error_invalid,
  131. 'foo': error_invalid,
  132. }
  133. self.assertFieldOutput(IDPhoneNumberField, valid, invalid)
  134. def test_IDPostCodeField(self):
  135. error_invalid = [u'Enter a valid post code']
  136. valid = {
  137. '12340': u'12340',
  138. '25412': u'25412',
  139. ' 12340 ': u'12340',
  140. }
  141. invalid = {
  142. '12 3 4 0': error_invalid,
  143. '12345': error_invalid,
  144. '10100': error_invalid,
  145. '123456': error_invalid,
  146. 'foo': error_invalid,
  147. }
  148. self.assertFieldOutput(IDPostCodeField, valid, invalid)
  149. def test_IDNationalIdentityNumberField(self):
  150. error_invalid = [u'Enter a valid NIK/KTP number']
  151. valid = {
  152. ' 12.3456.010178 3456 ': u'12.3456.010178.3456',
  153. '1234560101783456': u'12.3456.010178.3456',
  154. '12.3456.010101.3456': u'12.3456.010101.3456',
  155. }
  156. invalid = {
  157. '12.3456.310278.3456': error_invalid,
  158. '00.0000.010101.0000': error_invalid,
  159. '1234567890123456': error_invalid,
  160. 'foo': error_invalid,
  161. }
  162. self.assertFieldOutput(IDNationalIdentityNumberField, valid, invalid)
  163. def test_IDLicensePlateField(self):
  164. error_invalid = [u'Enter a valid vehicle license plate number']
  165. valid = {
  166. ' b 1234 ab ': u'B 1234 AB',
  167. 'B 1234 ABC': u'B 1234 ABC',
  168. 'A 12': u'A 12',
  169. 'DK 12345 12': u'DK 12345 12',
  170. 'RI 10': u'RI 10',
  171. 'CD 12 12': u'CD 12 12',
  172. }
  173. invalid = {
  174. 'CD 10 12': error_invalid,
  175. 'CD 1234 12': error_invalid,
  176. 'RI 10 AB': error_invalid,
  177. 'B 12345 01': error_invalid,
  178. 'N 1234 12': error_invalid,
  179. 'A 12 XYZ': error_invalid,
  180. 'Q 1234 AB': error_invalid,
  181. 'foo': error_invalid,
  182. }
  183. self.assertFieldOutput(IDLicensePlateField, valid, invalid)