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