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

/tests/regressiontests/forms/localflavor/be.py

https://code.google.com/p/mango-py/
Python | 79 lines | 74 code | 5 blank | 0 comment | 0 complexity | 4c8372c06b498d49100f2b88b74a53f0 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.contrib.localflavor.be.forms import (BEPostalCodeField,
  2. BEPhoneNumberField, BERegionSelect, BEProvinceSelect)
  3. from utils import LocalFlavorTestCase
  4. class BELocalFlavorTests(LocalFlavorTestCase):
  5. def test_BEPostalCodeField(self):
  6. error_format = [u'Enter a valid postal code in the range and format 1XXX - 9XXX.']
  7. valid = {
  8. u'1451': '1451',
  9. u'2540': '2540',
  10. }
  11. invalid = {
  12. '0287': error_format,
  13. '14309': error_format,
  14. '873': error_format,
  15. '35 74': error_format,
  16. '859A': error_format,
  17. }
  18. self.assertFieldOutput(BEPostalCodeField, valid, invalid)
  19. def test_BEPhoneNumberField(self):
  20. error_format = [
  21. ('Enter a valid phone number in one of the formats 0x xxx xx xx, '
  22. '0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, '
  23. '04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, '
  24. '0xxxxxxxx or 04xxxxxxxx.')
  25. ]
  26. valid = {
  27. u'01 234 56 78': '01 234 56 78',
  28. u'01/234.56.78': '01/234.56.78',
  29. u'01.234.56.78': '01.234.56.78',
  30. u'012 34 56 78': '012 34 56 78',
  31. u'012/34.56.78': '012/34.56.78',
  32. u'012.34.56.78': '012.34.56.78',
  33. u'0412 34 56 78': '0412 34 56 78',
  34. u'0412/34.56.78': '0412/34.56.78',
  35. u'0412.34.56.78': '0412.34.56.78',
  36. u'012345678': '012345678',
  37. u'0412345678': '0412345678',
  38. }
  39. invalid = {
  40. '01234567': error_format,
  41. '12/345.67.89': error_format,
  42. '012/345.678.90': error_format,
  43. '012/34.56.789': error_format,
  44. '0123/45.67.89': error_format,
  45. '012/345 678 90': error_format,
  46. '012/34 56 789': error_format,
  47. '012.34 56 789': error_format,
  48. }
  49. self.assertFieldOutput(BEPhoneNumberField, valid, invalid)
  50. def test_BERegionSelect(self):
  51. f = BERegionSelect()
  52. out = u'''<select name="regions">
  53. <option value="BRU">Brussels Capital Region</option>
  54. <option value="VLG" selected="selected">Flemish Region</option>
  55. <option value="WAL">Wallonia</option>
  56. </select>'''
  57. self.assertEqual(f.render('regions', 'VLG'), out)
  58. def test_BEProvinceSelect(self):
  59. f = BEProvinceSelect()
  60. out = u'''<select name="provinces">
  61. <option value="VAN">Antwerp</option>
  62. <option value="BRU">Brussels</option>
  63. <option value="VOV">East Flanders</option>
  64. <option value="VBR">Flemish Brabant</option>
  65. <option value="WHT">Hainaut</option>
  66. <option value="WLG" selected="selected">Liege</option>
  67. <option value="VLI">Limburg</option>
  68. <option value="WLX">Luxembourg</option>
  69. <option value="WNA">Namur</option>
  70. <option value="WBR">Walloon Brabant</option>
  71. <option value="VWV">West Flanders</option>
  72. </select>'''
  73. self.assertEqual(f.render('provinces', 'WLG'), out)