Code

Ticket #3988: patch.3.diff

File patch.3.diff, 7.2 KB (added by ttarabula, 7 years ago)
Line 
1Index: tests/regressiontests/forms/localflavor.py
2===================================================================
3--- tests/regressiontests/forms/localflavor.py  (revision 6194)
4+++ tests/regressiontests/forms/localflavor.py  (working copy)
5@@ -1818,4 +1818,222 @@
6 u''
7 >>> f.clean(u'')
8 u''
9+
10+# CAPostalCodeField ##############################################################
11+
12+CAPostalCodeField validates that the data is a six-character Canadian postal code.
13+>>> from django.contrib.localflavor.ca.forms import CAPostalCodeField
14+>>> f = CAPostalCodeField()
15+>>> f.clean('T2S 2H7')
16+u'T2S 2H7'
17+>>> f.clean('T2S 2H')
18+Traceback (most recent call last):
19+...
20+ValidationError: [u'Enter a postal code in the format XXX XXX.']
21+>>> f.clean('2T6 H8I')
22+Traceback (most recent call last):
23+...
24+ValidationError: [u'Enter a postal code in the format XXX XXX.']
25+>>> f.clean('T2S2H')
26+Traceback (most recent call last):
27+...
28+ValidationError: [u'Enter a postal code in the format XXX XXX.']
29+>>> f.clean(90210)
30+Traceback (most recent call last):
31+...
32+ValidationError: [u'Enter a postal code in the format XXX XXX.']
33+>>> f.clean(None)
34+Traceback (most recent call last):
35+...
36+ValidationError: [u'This field is required.']
37+>>> f.clean('')
38+Traceback (most recent call last):
39+...
40+ValidationError: [u'This field is required.']
41+>>> f = CAPostalCodeField(required=False)
42+>>> f.clean('T2S 2H7')
43+u'T2S 2H7'
44+>>> f.clean('T2S2H7')
45+Traceback (most recent call last):
46+...
47+ValidationError: [u'Enter a postal code in the format XXX XXX.']
48+>>> f.clean('T2S 2H')
49+Traceback (most recent call last):
50+...
51+ValidationError: [u'Enter a postal code in the format XXX XXX.']
52+>>> f.clean('2T6 H8I')
53+Traceback (most recent call last):
54+...
55+ValidationError: [u'Enter a postal code in the format XXX XXX.']
56+>>> f.clean('T2S2H')
57+Traceback (most recent call last):
58+...
59+ValidationError: [u'Enter a postal code in the format XXX XXX.']
60+>>> f.clean(90210)
61+Traceback (most recent call last):
62+...
63+ValidationError: [u'Enter a postal code in the format XXX XXX.']
64+>>> f.clean(None)
65+u''
66+>>> f.clean('')
67+u''
68+
69+# CAPhoneNumberField ##########################################################
70+
71+CAPhoneNumberField validates that the data is a valid Canadian phone number,
72+including the area code. It's normalized to XXX-XXX-XXXX format.
73+Note: This test is exactly the same as the USPhoneNumberField except using a real
74+Candian area code
75+
76+>>> from django.contrib.localflavor.ca.forms import CAPhoneNumberField
77+>>> f = CAPhoneNumberField()
78+>>> f.clean('403-555-1212')
79+u'403-555-1212'
80+>>> f.clean('4035551212')
81+u'403-555-1212'
82+>>> f.clean('403 555-1212')
83+u'403-555-1212'
84+>>> f.clean('(403) 555-1212')
85+u'403-555-1212'
86+>>> f.clean('403 555 1212')
87+u'403-555-1212'
88+>>> f.clean('403.555.1212')
89+u'403-555-1212'
90+>>> f.clean('403.555-1212')
91+u'403-555-1212'
92+>>> f.clean(' (403) 555.1212 ')
93+u'403-555-1212'
94+>>> f.clean('555-1212')
95+Traceback (most recent call last):
96+...
97+ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
98+>>> f.clean('403-55-1212')
99+Traceback (most recent call last):
100+...
101+ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
102+>>> f.clean(None)
103+Traceback (most recent call last):
104+...
105+ValidationError: [u'This field is required.']
106+>>> f.clean('')
107+Traceback (most recent call last):
108+...
109+ValidationError: [u'This field is required.']
110+
111+>>> f = CAPhoneNumberField(required=False)
112+>>> f.clean('403-555-1212')
113+u'403-555-1212'
114+>>> f.clean('4035551212')
115+u'403-555-1212'
116+>>> f.clean('403 555-1212')
117+u'403-555-1212'
118+>>> f.clean('(403) 555-1212')
119+u'403-555-1212'
120+>>> f.clean('403 555 1212')
121+u'403-555-1212'
122+>>> f.clean('403.555.1212')
123+u'403-555-1212'
124+>>> f.clean('403.555-1212')
125+u'403-555-1212'
126+>>> f.clean(' (403) 555.1212 ')
127+u'403-555-1212'
128+>>> f.clean('555-1212')
129+Traceback (most recent call last):
130+...
131+ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
132+>>> f.clean('403-55-1212')
133+Traceback (most recent call last):
134+...
135+ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
136+>>> f.clean(None)
137+u''
138+>>> f.clean('')
139+u''
140+
141+# CAProvinceField ################################################################
142+
143+CAProvinceField validates that the data is either an abbreviation or name of a
144+Canadian province.
145+>>> from django.contrib.localflavor.ca.forms import CAProvinceField
146+>>> f = CAProvinceField()
147+>>> f.clean('ab')
148+u'AB'
149+>>> f.clean('BC')
150+u'BC'
151+>>> f.clean('nova scotia')
152+u'NS'
153+>>> f.clean('  manitoba ')
154+u'MB'
155+>>> f.clean('T2S 2H7')
156+Traceback (most recent call last):
157+...
158+ValidationError: [u'Enter a Canadian province or territory.']
159+>>> f.clean(None)
160+Traceback (most recent call last):
161+...
162+ValidationError: [u'This field is required.']
163+>>> f.clean('')
164+Traceback (most recent call last):
165+...
166+ValidationError: [u'This field is required.']
167+
168+>>> f = CAProvinceField(required=False)
169+>>> f.clean('ab')
170+u'AB'
171+>>> f.clean('BC')
172+u'BC'
173+>>> f.clean('nova scotia')
174+u'NS'
175+>>> f.clean('  manitoba ')
176+u'MB'
177+>>> f.clean('T2S 2H7')
178+Traceback (most recent call last):
179+...
180+ValidationError: [u'Enter a Canadian province or territory.']
181+>>> f.clean(None)
182+u''
183+>>> f.clean('')
184+u''
185+
186+# CAProvinceSelect ###############################################################
187+
188+CAProvinceSelect is a Select widget that uses a list of Canadian provinces/territories
189+as its choices.
190+>>> from django.contrib.localflavor.ca.forms import CAProvinceSelect
191+>>> w = CAProvinceSelect()
192+>>> print w.render('province', 'AB')
193+<select name="province">
194+<option value="AB" selected="selected">Alberta</option>
195+<option value="BC">British Columbia</option>
196+<option value="MB">Manitoba</option>
197+<option value="NB">New Brunswick</option>
198+<option value="NF">Newfoundland and Labrador</option>
199+<option value="NT">Northwest Territories</option>
200+<option value="NS">Nova Scotia</option>
201+<option value="NU">Nunavut</option>
202+<option value="ON">Ontario</option>
203+<option value="PE">Prince Edward Island</option>
204+<option value="QC">Quebec</option>
205+<option value="SK">Saskatchewan</option>
206+<option value="YK">Yukon</option>
207+</select>
208+
209+# CASocialInsuranceNumberField #################################################
210+>>> from django.contrib.localflavor.ca.forms import CASocialInsuranceNumberField
211+>>> f = CASocialInsuranceNumberField()
212+>>> f.clean('046-454-286')
213+u'046-454-286'
214+>>> f.clean('046-454-287')
215+Traceback (most recent call last):
216+...
217+ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
218+>>> f.clean('046 454 286')
219+Traceback (most recent call last):
220+...
221+ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
222+>>> f.clean('046-44-286')
223+Traceback (most recent call last):
224+...
225+ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
226+
227 """
228Index: AUTHORS
229===================================================================
230--- AUTHORS     (revision 6194)
231+++ AUTHORS     (working copy)
232@@ -274,6 +274,7 @@
233     Swaroop C H <http://www.swaroopch.info>
234     Aaron Swartz <http://www.aaronsw.com/>
235     Ville Säävuori <http://www.unessa.net/>
236+    Tyler Tarabula <tyler.tarabula@gmail.com>
237     Tyson Tate <tyson@fallingbullets.com>
238     Frank Tegtmeyer <fte@fte.to>
239     thebjorn <bp@datakortet.no>