App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / regressiontests / localflavor / ca / tests.py
blob05d2fe2ac4a0bc137c03e7cee3a8c38ef6e7232b
1 import warnings
3 from django.contrib.localflavor.ca.forms import (CAPostalCodeField,
4 CAPhoneNumberField, CAProvinceField, CAProvinceSelect,
5 CASocialInsuranceNumberField)
7 from django.test import SimpleTestCase
10 class CALocalFlavorTests(SimpleTestCase):
11 def setUp(self):
12 self.save_warnings_state()
13 warnings.filterwarnings(
14 "ignore",
15 category=RuntimeWarning,
16 module='django.contrib.localflavor.ca.ca_provinces'
19 def tearDown(self):
20 self.restore_warnings_state()
22 def test_CAProvinceSelect(self):
23 f = CAProvinceSelect()
24 out = u'''<select name="province">
25 <option value="AB" selected="selected">Alberta</option>
26 <option value="BC">British Columbia</option>
27 <option value="MB">Manitoba</option>
28 <option value="NB">New Brunswick</option>
29 <option value="NL">Newfoundland and Labrador</option>
30 <option value="NT">Northwest Territories</option>
31 <option value="NS">Nova Scotia</option>
32 <option value="NU">Nunavut</option>
33 <option value="ON">Ontario</option>
34 <option value="PE">Prince Edward Island</option>
35 <option value="QC">Quebec</option>
36 <option value="SK">Saskatchewan</option>
37 <option value="YT">Yukon</option>
38 </select>'''
39 self.assertHTMLEqual(f.render('province', 'AB'), out)
41 def test_CAPostalCodeField(self):
42 error_format = [u'Enter a postal code in the format XXX XXX.']
43 valid = {
44 'T2S 2H7': 'T2S 2H7',
45 'T2S 2W7': 'T2S 2W7',
46 'T2S 2Z7': 'T2S 2Z7',
47 'T2Z 2H7': 'T2Z 2H7',
48 'T2S2H7' : 'T2S 2H7',
49 't2s 2h7': 'T2S 2H7',
50 't2s2h7' : 'T2S 2H7',
51 't2s 2H7': 'T2S 2H7',
52 ' t2s 2H7 ': 'T2S 2H7',
54 invalid = {
55 'T2S 2H' : error_format,
56 '2T6 H8I': error_format,
57 'T2S2H' : error_format,
58 't2s h8i': error_format,
59 90210 : error_format,
60 'W2S 2H3': error_format,
61 'Z2S 2H3': error_format,
62 'F2S 2H3': error_format,
63 'A2S 2D3': error_format,
64 'A2I 2R3': error_format,
65 'A2Q 2R3': error_format,
66 'U2B 2R3': error_format,
67 'O2B 2R3': error_format,
69 self.assertFieldOutput(CAPostalCodeField, valid, invalid)
71 def test_CAPhoneNumberField(self):
72 error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
73 valid = {
74 '403-555-1212': '403-555-1212',
75 '4035551212': '403-555-1212',
76 '403 555-1212': '403-555-1212',
77 '(403) 555-1212': '403-555-1212',
78 '403 555 1212': '403-555-1212',
79 '403.555.1212': '403-555-1212',
80 '403.555-1212': '403-555-1212',
81 ' (403) 555.1212 ': '403-555-1212',
83 invalid = {
84 '555-1212': error_format,
85 '403-55-1212': error_format,
87 self.assertFieldOutput(CAPhoneNumberField, valid, invalid)
89 def test_CAProvinceField(self):
90 error_format = [u'Enter a Canadian province or territory.']
91 valid = {
92 'ab': 'AB',
93 'BC': 'BC',
94 'nova scotia': 'NS',
95 ' manitoba ': 'MB',
97 invalid = {
98 'T2S 2H7': error_format,
100 self.assertFieldOutput(CAProvinceField, valid, invalid)
102 def test_CASocialInsuranceField(self):
103 error_format = [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXX format.']
104 valid = {
105 '046-454-286': '046-454-286',
107 invalid = {
108 '046-454-287': error_format,
109 '046 454 286': error_format,
110 '046-44-286': error_format,
112 self.assertFieldOutput(CASocialInsuranceNumberField, valid, invalid)