Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Converted Belerusian localflavor tests to use the new, less verbose f…

…ormat. Thanks to Idan Gazit for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14932 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b035759199cce68164402e2dc1bc2b72de6aca2d 1 parent c9b79c5
@alex alex authored
Showing with 72 additions and 87 deletions.
  1. +72 −87 tests/regressiontests/forms/localflavor/be.py
View
159 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')
+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_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')
+ 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_region_field(self):
- w = BERegionSelect()
- self.assertEqual(u'<select name="regions">\n<option value="BRU">Brussels Capital Region</option>\n<option value="VLG" selected="selected">Flemish Region</option>\n<option value="WAL">Wallonia</option>\n</select>', w.render('regions', 'VLG'))
+ def test_BERegionSelect(self):
+ f = BERegionSelect()
+ out = u'''<select name="regions">
+<option value="BRU">Brussels Capital Region</option>
+<option value="VLG" selected="selected">Flemish Region</option>
+<option value="WAL">Wallonia</option>
+</select>'''
+ self.assertEqual(f.render('regions', 'VLG'), out)
- def test_province_field(self):
- w = BEProvinceSelect()
- self.assertEqual(u'<select name="provinces">\n<option value="VAN">Antwerp</option>\n<option value="BRU">Brussels</option>\n<option value="VOV">East Flanders</option>\n<option value="VBR">Flemish Brabant</option>\n<option value="WHT">Hainaut</option>\n<option value="WLG" selected="selected">Liege</option>\n<option value="VLI">Limburg</option>\n<option value="WLX">Luxembourg</option>\n<option value="WNA">Namur</option>\n<option value="WBR">Walloon Brabant</option>\n<option value="VWV">West Flanders</option>\n</select>', w.render('provinces', 'WLG'))
+ def test_BEProvinceSelect(self):
+ f = BEProvinceSelect()
+ out = u'''<select name="provinces">
+<option value="VAN">Antwerp</option>
+<option value="BRU">Brussels</option>
+<option value="VOV">East Flanders</option>
+<option value="VBR">Flemish Brabant</option>
+<option value="WHT">Hainaut</option>
+<option value="WLG" selected="selected">Liege</option>
+<option value="VLI">Limburg</option>
+<option value="WLX">Luxembourg</option>
+<option value="WNA">Namur</option>
+<option value="WBR">Walloon Brabant</option>
+<option value="VWV">West Flanders</option>
+</select>'''
+ self.assertEqual(f.render('provinces', 'WLG'), out)
Please sign in to comment.
Something went wrong with that request. Please try again.