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
):
12 self
.save_warnings_state()
13 warnings
.filterwarnings(
15 category
=RuntimeWarning,
16 module
='django.contrib.localflavor.ca.ca_provinces'
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>
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.']
52 ' t2s 2H7 ': 'T2S 2H7',
55 'T2S 2H' : error_format
,
56 '2T6 H8I': error_format
,
57 'T2S2H' : error_format
,
58 't2s h8i': 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.']
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',
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.']
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.']
105 '046-454-286': '046-454-286',
108 '046-454-287': error_format
,
109 '046 454 286': error_format
,
110 '046-44-286': error_format
,
112 self
.assertFieldOutput(CASocialInsuranceNumberField
, valid
, invalid
)