diff --git a/tests/regressiontests/forms/localflavor/be.py b/tests/regressiontests/forms/localflavor/be.py
index 71b18003c6..c68bc7d6d7 100644
--- a/tests/regressiontests/forms/localflavor/be.py
+++ b/tests/regressiontests/forms/localflavor/be.py
@@ -1,94 +1,79 @@
-from django.test import TestCase
-from django.forms import *
-
from django.contrib.localflavor.be.forms import (BEPostalCodeField,
BEPhoneNumberField, BERegionSelect, BEProvinceSelect)
-class BELocalFlavorTests(TestCase):
- """
- Test case to validate BE localflavor
- """
- def assertRaisesErrorWithMessage(self, error, message, callable, *args, **kwargs):
- self.assertRaises(error, callable, *args, **kwargs)
- try:
- callable(*args, **kwargs)
- except error, e:
- self.assertEqual(message, str(e))
+from utils import LocalFlavorTestCase
- def test_postal_code_field(self):
- f = BEPostalCodeField()
- self.assertEqual(u'1451', f.clean('1451'))
- self.assertEqual(u'2540', f.clean('2540'))
- err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
- err_message = "[u'This field is required.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
- f = BEPostalCodeField(required=False)
- self.assertEqual(u'1451', f.clean('1451'))
- self.assertEqual(u'2540', f.clean('2540'))
- self.assertEqual(u'', f.clean(''))
- err_message = "[u'Enter a valid postal code in the range and format 1XXX - 9XXX.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0287')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '14309')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '873')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '35 74')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '859A')
- def test_phone_number_field(self):
- f = BEPhoneNumberField()
- self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
- self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
- self.assertEqual(u'01.234.56.78', f.clean('01.234.56.78'))
- self.assertEqual(u'012 34 56 78', f.clean('012 34 56 78'))
- self.assertEqual(u'012/34.56.78', f.clean('012/34.56.78'))
- self.assertEqual(u'012.34.56.78', f.clean('012.34.56.78'))
- self.assertEqual(u'0412 34 56 78', f.clean('0412 34 56 78'))
- self.assertEqual(u'0412/34.56.78', f.clean('0412/34.56.78'))
- self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
- self.assertEqual(u'012345678', f.clean('012345678'))
- self.assertEqual(u'0412345678', f.clean('0412345678'))
- err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, 0xxxxxxxx or 04xxxxxxxx.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
- err_message = "[u'This field is required.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '')
- f = BEPhoneNumberField(required=False)
- self.assertEqual(u'01 234 56 78', f.clean('01 234 56 78'))
- self.assertEqual(u'01/234.56.78', f.clean('01/234.56.78'))
- self.assertEqual(u'01.234.56.78', f.clean('01.234.56.78'))
- self.assertEqual(u'012 34 56 78', f.clean('012 34 56 78'))
- self.assertEqual(u'012/34.56.78', f.clean('012/34.56.78'))
- self.assertEqual(u'012.34.56.78', f.clean('012.34.56.78'))
- self.assertEqual(u'0412 34 56 78', f.clean('0412 34 56 78'))
- self.assertEqual(u'0412/34.56.78', f.clean('0412/34.56.78'))
- self.assertEqual(u'0412.34.56.78', f.clean('0412.34.56.78'))
- self.assertEqual(u'012345678', f.clean('012345678'))
- self.assertEqual(u'0412345678', f.clean('0412345678'))
- self.assertEqual(u'', f.clean(''))
- err_message = "[u'Enter a valid phone number in one of the formats 0x xxx xx xx, 0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, 04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, 0xxxxxxxx or 04xxxxxxxx.']"
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '01234567')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '12/345.67.89')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345.678.90')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34.56.789')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '0123/45.67.89')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/345 678 90')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012/34 56 789')
- self.assertRaisesErrorWithMessage(ValidationError, err_message, f.clean, '012.34 56 789')
+class BELocalFlavorTests(LocalFlavorTestCase):
+ def test_BEPostalCodeField(self):
+ error_format = [u'Enter a valid postal code in the range and format 1XXX - 9XXX.']
+ valid = {
+ u'1451': '1451',
+ u'2540': '2540',
+ }
+ invalid = {
+ '0287': error_format,
+ '14309': error_format,
+ '873': error_format,
+ '35 74': error_format,
+ '859A': error_format,
+ }
+ self.assertFieldOutput(BEPostalCodeField, valid, invalid)
- def test_region_field(self):
- w = BERegionSelect()
- self.assertEqual(u'', w.render('regions', 'VLG'))
+ def test_BEPhoneNumberField(self):
+ error_format = [
+ ('Enter a valid phone number in one of the formats 0x xxx xx xx, '
+ '0xx xx xx xx, 04xx xx xx xx, 0x/xxx.xx.xx, 0xx/xx.xx.xx, '
+ '04xx/xx.xx.xx, 0x.xxx.xx.xx, 0xx.xx.xx.xx, 04xx.xx.xx.xx, '
+ '0xxxxxxxx or 04xxxxxxxx.')
+ ]
+ valid = {
+ u'01 234 56 78': '01 234 56 78',
+ u'01/234.56.78': '01/234.56.78',
+ u'01.234.56.78': '01.234.56.78',
+ u'012 34 56 78': '012 34 56 78',
+ u'012/34.56.78': '012/34.56.78',
+ u'012.34.56.78': '012.34.56.78',
+ u'0412 34 56 78': '0412 34 56 78',
+ u'0412/34.56.78': '0412/34.56.78',
+ u'0412.34.56.78': '0412.34.56.78',
+ u'012345678': '012345678',
+ u'0412345678': '0412345678',
+ }
+ invalid = {
+ '01234567': error_format,
+ '12/345.67.89': error_format,
+ '012/345.678.90': error_format,
+ '012/34.56.789': error_format,
+ '0123/45.67.89': error_format,
+ '012/345 678 90': error_format,
+ '012/34 56 789': error_format,
+ '012.34 56 789': error_format,
+ }
+ self.assertFieldOutput(BEPhoneNumberField, valid, invalid)
- def test_province_field(self):
- w = BEProvinceSelect()
- self.assertEqual(u'', w.render('provinces', 'WLG'))
+ def test_BERegionSelect(self):
+ f = BERegionSelect()
+ out = u''''''
+ self.assertEqual(f.render('regions', 'VLG'), out)
+
+ def test_BEProvinceSelect(self):
+ f = BEProvinceSelect()
+ out = u''''''
+ self.assertEqual(f.render('provinces', 'WLG'), out)