PageRenderTime 35ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/br.py

https://code.google.com/p/mango-py/
Python | 144 lines | 136 code | 7 blank | 1 comment | 0 complexity | 56fe5b3fb201936247878ecdb2763981 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.localflavor.br.forms import (BRZipCodeField,
  2. BRCNPJField, BRCPFField, BRPhoneNumberField, BRStateSelect,
  3. BRStateChoiceField)
  4. from utils import LocalFlavorTestCase
  5. class BRLocalFlavorTests(LocalFlavorTestCase):
  6. def test_BRZipCodeField(self):
  7. error_format = [u'Enter a zip code in the format XXXXX-XXX.']
  8. valid = {
  9. '12345-123': '12345-123',
  10. }
  11. invalid = {
  12. '12345_123': error_format,
  13. '1234-123': error_format,
  14. 'abcde-abc': error_format,
  15. '12345-': error_format,
  16. '-123': error_format,
  17. }
  18. self.assertFieldOutput(BRZipCodeField, valid, invalid)
  19. def test_BRCNPJField(self):
  20. error_format = [u'Invalid CNPJ number.']
  21. error_numbersonly = [u'This field requires only numbers.']
  22. valid = {
  23. '64.132.916/0001-88': '64.132.916/0001-88',
  24. '64-132-916/0001-88': '64-132-916/0001-88',
  25. '64132916/0001-88': '64132916/0001-88',
  26. }
  27. invalid = {
  28. '12-345-678/9012-10': error_format,
  29. '12.345.678/9012-10': error_format,
  30. '12345678/9012-10': error_format,
  31. '64.132.916/0001-XX': error_numbersonly,
  32. }
  33. self.assertFieldOutput(BRCNPJField, valid, invalid)
  34. def test_BRCPFField(self):
  35. error_format = [u'Invalid CPF number.']
  36. error_numbersonly = [u'This field requires only numbers.']
  37. error_atmost_chars = [u'Ensure this value has at most 14 characters (it has 15).']
  38. error_atleast_chars = [u'Ensure this value has at least 11 characters (it has 10).']
  39. error_atmost = [u'This field requires at most 11 digits or 14 characters.']
  40. valid = {
  41. '663.256.017-26': '663.256.017-26',
  42. '66325601726': '66325601726',
  43. '375.788.573-20': '375.788.573-20',
  44. '84828509895': '84828509895',
  45. }
  46. invalid = {
  47. '489.294.654-54': error_format,
  48. '295.669.575-98': error_format,
  49. '539.315.127-22': error_format,
  50. '375.788.573-XX': error_numbersonly,
  51. '375.788.573-000': error_atmost_chars,
  52. '123.456.78': error_atleast_chars,
  53. '123456789555': error_atmost,
  54. }
  55. self.assertFieldOutput(BRCPFField, valid, invalid)
  56. def test_BRPhoneNumberField(self):
  57. # TODO: this doesn't test for any invalid inputs.
  58. valid = {
  59. '41-3562-3464': u'41-3562-3464',
  60. '4135623464': u'41-3562-3464',
  61. '41 3562-3464': u'41-3562-3464',
  62. '41 3562 3464': u'41-3562-3464',
  63. '(41) 3562 3464': u'41-3562-3464',
  64. '41.3562.3464': u'41-3562-3464',
  65. '41.3562-3464': u'41-3562-3464',
  66. ' (41) 3562.3464': u'41-3562-3464',
  67. }
  68. invalid = {}
  69. self.assertFieldOutput(BRPhoneNumberField, valid, invalid)
  70. def test_BRStateSelect(self):
  71. f = BRStateSelect()
  72. out = u'''<select name="states">
  73. <option value="AC">Acre</option>
  74. <option value="AL">Alagoas</option>
  75. <option value="AP">Amap\xe1</option>
  76. <option value="AM">Amazonas</option>
  77. <option value="BA">Bahia</option>
  78. <option value="CE">Cear\xe1</option>
  79. <option value="DF">Distrito Federal</option>
  80. <option value="ES">Esp\xedrito Santo</option>
  81. <option value="GO">Goi\xe1s</option>
  82. <option value="MA">Maranh\xe3o</option>
  83. <option value="MT">Mato Grosso</option>
  84. <option value="MS">Mato Grosso do Sul</option>
  85. <option value="MG">Minas Gerais</option>
  86. <option value="PA">Par\xe1</option>
  87. <option value="PB">Para\xedba</option>
  88. <option value="PR" selected="selected">Paran\xe1</option>
  89. <option value="PE">Pernambuco</option>
  90. <option value="PI">Piau\xed</option>
  91. <option value="RJ">Rio de Janeiro</option>
  92. <option value="RN">Rio Grande do Norte</option>
  93. <option value="RS">Rio Grande do Sul</option>
  94. <option value="RO">Rond\xf4nia</option>
  95. <option value="RR">Roraima</option>
  96. <option value="SC">Santa Catarina</option>
  97. <option value="SP">S\xe3o Paulo</option>
  98. <option value="SE">Sergipe</option>
  99. <option value="TO">Tocantins</option>
  100. </select>'''
  101. self.assertEqual(f.render('states', 'PR'), out)
  102. def test_BRStateChoiceField(self):
  103. error_invalid = [u'Select a valid brazilian state. That state is not one of the available states.']
  104. valid = {
  105. 'AC': 'AC',
  106. 'AL': 'AL',
  107. 'AP': 'AP',
  108. 'AM': 'AM',
  109. 'BA': 'BA',
  110. 'CE': 'CE',
  111. 'DF': 'DF',
  112. 'ES': 'ES',
  113. 'GO': 'GO',
  114. 'MA': 'MA',
  115. 'MT': 'MT',
  116. 'MS': 'MS',
  117. 'MG': 'MG',
  118. 'PA': 'PA',
  119. 'PB': 'PB',
  120. 'PR': 'PR',
  121. 'PE': 'PE',
  122. 'PI': 'PI',
  123. 'RJ': 'RJ',
  124. 'RN': 'RN',
  125. 'RS': 'RS',
  126. 'RO': 'RO',
  127. 'RR': 'RR',
  128. 'SC': 'SC',
  129. 'SP': 'SP',
  130. 'SE': 'SE',
  131. 'TO': 'TO',
  132. }
  133. invalid = {
  134. 'pr': error_invalid,
  135. }
  136. self.assertFieldOutput(BRStateChoiceField, valid, invalid)