2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2010-10-11 23:35:23 +00:00
|
|
|
from django.contrib.localflavor.be.forms import (BEPostalCodeField,
|
|
|
|
BEPhoneNumberField, BERegionSelect, BEProvinceSelect)
|
|
|
|
|
2011-08-23 02:32:37 +00:00
|
|
|
from django.test import SimpleTestCase
|
2010-12-18 20:29:16 +00:00
|
|
|
|
2010-10-11 23:35:23 +00:00
|
|
|
|
2011-08-23 02:32:37 +00:00
|
|
|
class BELocalFlavorTests(SimpleTestCase):
|
2010-12-18 20:29:16 +00:00
|
|
|
def test_BEPostalCodeField(self):
|
2012-06-07 16:08:47 +00:00
|
|
|
error_format = ['Enter a valid postal code in the range and format 1XXX - 9XXX.']
|
2010-12-18 20:29:16 +00:00
|
|
|
valid = {
|
2012-06-07 16:08:47 +00:00
|
|
|
'1451': '1451',
|
|
|
|
'2540': '2540',
|
2010-12-18 20:29:16 +00:00
|
|
|
}
|
|
|
|
invalid = {
|
|
|
|
'0287': error_format,
|
|
|
|
'14309': error_format,
|
|
|
|
'873': error_format,
|
|
|
|
'35 74': error_format,
|
|
|
|
'859A': error_format,
|
|
|
|
}
|
|
|
|
self.assertFieldOutput(BEPostalCodeField, valid, invalid)
|
2010-10-11 23:35:23 +00:00
|
|
|
|
2010-12-18 20:29:16 +00:00
|
|
|
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 = {
|
2012-06-07 16:08:47 +00:00
|
|
|
'01 234 56 78': '01 234 56 78',
|
|
|
|
'01/234.56.78': '01/234.56.78',
|
|
|
|
'01.234.56.78': '01.234.56.78',
|
|
|
|
'012 34 56 78': '012 34 56 78',
|
|
|
|
'012/34.56.78': '012/34.56.78',
|
|
|
|
'012.34.56.78': '012.34.56.78',
|
|
|
|
'0412 34 56 78': '0412 34 56 78',
|
|
|
|
'0412/34.56.78': '0412/34.56.78',
|
|
|
|
'0412.34.56.78': '0412.34.56.78',
|
|
|
|
'012345678': '012345678',
|
|
|
|
'0412345678': '0412345678',
|
2010-12-18 20:29:16 +00:00
|
|
|
}
|
|
|
|
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)
|
2010-10-11 23:35:23 +00:00
|
|
|
|
2010-12-18 20:29:16 +00:00
|
|
|
def test_BERegionSelect(self):
|
|
|
|
f = BERegionSelect()
|
2012-06-07 16:08:47 +00:00
|
|
|
out = '''<select name="regions">
|
2010-12-18 20:29:16 +00:00
|
|
|
<option value="BRU">Brussels Capital Region</option>
|
|
|
|
<option value="VLG" selected="selected">Flemish Region</option>
|
|
|
|
<option value="WAL">Wallonia</option>
|
|
|
|
</select>'''
|
2012-01-31 20:36:11 +00:00
|
|
|
self.assertHTMLEqual(f.render('regions', 'VLG'), out)
|
2010-10-11 23:35:23 +00:00
|
|
|
|
2010-12-18 20:29:16 +00:00
|
|
|
def test_BEProvinceSelect(self):
|
|
|
|
f = BEProvinceSelect()
|
2012-06-07 16:08:47 +00:00
|
|
|
out = '''<select name="provinces">
|
2010-12-18 20:29:16 +00:00
|
|
|
<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>'''
|
2012-01-31 20:36:11 +00:00
|
|
|
self.assertHTMLEqual(f.render('provinces', 'WLG'), out)
|