PageRenderTime 51ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/ar.py

https://code.google.com/p/mango-py/
Python | 99 lines | 96 code | 3 blank | 0 comment | 3 complexity | dd4e5135357bccee88ebbc89e6892f98 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.localflavor.ar.forms import (ARProvinceSelect,
  2. ARPostalCodeField, ARDNIField, ARCUITField)
  3. from utils import LocalFlavorTestCase
  4. class ARLocalFlavorTests(LocalFlavorTestCase):
  5. def test_ARProvinceSelect(self):
  6. f = ARProvinceSelect()
  7. out = u'''<select name="provincias">
  8. <option value="B">Buenos Aires</option>
  9. <option value="K">Catamarca</option>
  10. <option value="H">Chaco</option>
  11. <option value="U">Chubut</option>
  12. <option value="C">Ciudad Aut\xf3noma de Buenos Aires</option>
  13. <option value="X">C\xf3rdoba</option>
  14. <option value="W">Corrientes</option>
  15. <option value="E">Entre R\xedos</option>
  16. <option value="P">Formosa</option>
  17. <option value="Y">Jujuy</option>
  18. <option value="L">La Pampa</option>
  19. <option value="F">La Rioja</option>
  20. <option value="M">Mendoza</option>
  21. <option value="N">Misiones</option>
  22. <option value="Q">Neuqu\xe9n</option>
  23. <option value="R">R\xedo Negro</option>
  24. <option value="A" selected="selected">Salta</option>
  25. <option value="J">San Juan</option>
  26. <option value="D">San Luis</option>
  27. <option value="Z">Santa Cruz</option>
  28. <option value="S">Santa Fe</option>
  29. <option value="G">Santiago del Estero</option>
  30. <option value="V">Tierra del Fuego, Ant\xe1rtida e Islas del Atl\xe1ntico Sur</option>
  31. <option value="T">Tucum\xe1n</option>
  32. </select>'''
  33. self.assertEqual(f.render('provincias', 'A'), out)
  34. def test_ARPostalCodeField(self):
  35. error_format = [u'Enter a postal code in the format NNNN or ANNNNAAA.']
  36. error_atmost = [u'Ensure this value has at most 8 characters (it has 9).']
  37. error_atleast = [u'Ensure this value has at least 4 characters (it has 3).']
  38. valid = {
  39. '5000': '5000',
  40. 'C1064AAB': 'C1064AAB',
  41. 'c1064AAB': 'C1064AAB',
  42. 'C1064aab': 'C1064AAB',
  43. '4400': '4400',
  44. u'C1064AAB': 'C1064AAB',
  45. }
  46. invalid = {
  47. 'C1064AABB': error_atmost + error_format,
  48. 'C1064AA': error_format,
  49. 'C1064AB': error_format,
  50. '106AAB': error_format,
  51. '500': error_atleast + error_format,
  52. '5PPP': error_format,
  53. }
  54. self.assertFieldOutput(ARPostalCodeField, valid, invalid)
  55. def test_ARDNIField(self):
  56. error_length = [u'This field requires 7 or 8 digits.']
  57. error_digitsonly = [u'This field requires only numbers.']
  58. valid = {
  59. '20123456': '20123456',
  60. '20.123.456': '20123456',
  61. u'20123456': '20123456',
  62. u'20.123.456': '20123456',
  63. '20.123456': '20123456',
  64. '9123456': '9123456',
  65. '9.123.456': '9123456',
  66. }
  67. invalid = {
  68. '101234566': error_length,
  69. 'W0123456': error_digitsonly,
  70. '10,123,456': error_digitsonly,
  71. }
  72. self.assertFieldOutput(ARDNIField, valid, invalid)
  73. def test_ARCUITField(self):
  74. error_format = [u'Enter a valid CUIT in XX-XXXXXXXX-X or XXXXXXXXXXXX format.']
  75. error_invalid = [u'Invalid CUIT.']
  76. valid = {
  77. '20-10123456-9': '20-10123456-9',
  78. u'20-10123456-9': '20-10123456-9',
  79. '27-10345678-4': '27-10345678-4',
  80. '20101234569': '20-10123456-9',
  81. '27103456784': '27-10345678-4',
  82. }
  83. invalid = {
  84. '2-10123456-9': error_format,
  85. '210123456-9': error_format,
  86. '20-10123456': error_format,
  87. '20-10123456-': error_format,
  88. '20-10123456-5': error_invalid,
  89. '2-10123456-9': error_format,
  90. '27-10345678-1': error_invalid,
  91. u'27-10345678-1': error_invalid,
  92. }
  93. self.assertFieldOutput(ARCUITField, valid, invalid)