Ticket #3988: patch.2.diff

File patch.2.diff, 7.2 KB (added by ttarabula, 7 years ago)
  • tests/regressiontests/forms/localflavor.py

     
    18181818u''
    18191819>>> f.clean(u'')
    18201820u''
     1821
     1822# CAPostalCodeField ##############################################################
     1823
     1824CAPostalCodeField validates that the data is a six-character Canadian postal code.
     1825>>> from django.contrib.localflavor.ca.forms import CAPostalCodeField
     1826>>> f = CAPostalCodeField()
     1827>>> f.clean('T2S 2H7')
     1828u'T2S 2H7'
     1829>>> f.clean('T2S 2H')
     1830Traceback (most recent call last):
     1831...
     1832ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1833>>> f.clean('2T6 H8I')
     1834Traceback (most recent call last):
     1835...
     1836ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1837>>> f.clean('T2S2H')
     1838Traceback (most recent call last):
     1839...
     1840ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1841>>> f.clean(90210)
     1842Traceback (most recent call last):
     1843...
     1844ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1845>>> f.clean(None)
     1846Traceback (most recent call last):
     1847...
     1848ValidationError: [u'This field is required.']
     1849>>> f.clean('')
     1850Traceback (most recent call last):
     1851...
     1852ValidationError: [u'This field is required.']
     1853>>> f = CAPostalCodeField(required=False)
     1854>>> f.clean('T2S 2H7')
     1855u'T2S 2H7'
     1856>>> f.clean('T2S2H7')
     1857Traceback (most recent call last):
     1858...
     1859ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1860>>> f.clean('T2S 2H')
     1861Traceback (most recent call last):
     1862...
     1863ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1864>>> f.clean('2T6 H8I')
     1865Traceback (most recent call last):
     1866...
     1867ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1868>>> f.clean('T2S2H')
     1869Traceback (most recent call last):
     1870...
     1871ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1872>>> f.clean(90210)
     1873Traceback (most recent call last):
     1874...
     1875ValidationError: [u'Enter a postal code in the format XXX XXX.']
     1876>>> f.clean(None)
     1877u''
     1878>>> f.clean('')
     1879u''
     1880
     1881# CAPhoneNumberField ##########################################################
     1882
     1883CAPhoneNumberField validates that the data is a valid Canadian phone number,
     1884including the area code. It's normalized to XXX-XXX-XXXX format.
     1885Note: This test is exactly the same as the USPhoneNumberField except using a real
     1886Candian area code
     1887
     1888>>> from django.contrib.localflavor.ca.forms import CAPhoneNumberField
     1889>>> f = CAPhoneNumberField()
     1890>>> f.clean('403-555-1212')
     1891u'403-555-1212'
     1892>>> f.clean('4035551212')
     1893u'403-555-1212'
     1894>>> f.clean('403 555-1212')
     1895u'403-555-1212'
     1896>>> f.clean('(403) 555-1212')
     1897u'403-555-1212'
     1898>>> f.clean('403 555 1212')
     1899u'403-555-1212'
     1900>>> f.clean('403.555.1212')
     1901u'403-555-1212'
     1902>>> f.clean('403.555-1212')
     1903u'403-555-1212'
     1904>>> f.clean(' (403) 555.1212 ')
     1905u'403-555-1212'
     1906>>> f.clean('555-1212')
     1907Traceback (most recent call last):
     1908...
     1909ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
     1910>>> f.clean('403-55-1212')
     1911Traceback (most recent call last):
     1912...
     1913ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
     1914>>> f.clean(None)
     1915Traceback (most recent call last):
     1916...
     1917ValidationError: [u'This field is required.']
     1918>>> f.clean('')
     1919Traceback (most recent call last):
     1920...
     1921ValidationError: [u'This field is required.']
     1922
     1923>>> f = CAPhoneNumberField(required=False)
     1924>>> f.clean('403-555-1212')
     1925u'403-555-1212'
     1926>>> f.clean('4035551212')
     1927u'403-555-1212'
     1928>>> f.clean('403 555-1212')
     1929u'403-555-1212'
     1930>>> f.clean('(403) 555-1212')
     1931u'403-555-1212'
     1932>>> f.clean('403 555 1212')
     1933u'403-555-1212'
     1934>>> f.clean('403.555.1212')
     1935u'403-555-1212'
     1936>>> f.clean('403.555-1212')
     1937u'403-555-1212'
     1938>>> f.clean(' (403) 555.1212 ')
     1939u'403-555-1212'
     1940>>> f.clean('555-1212')
     1941Traceback (most recent call last):
     1942...
     1943ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
     1944>>> f.clean('403-55-1212')
     1945Traceback (most recent call last):
     1946...
     1947ValidationError: [u'Phone numbers must be in XXX-XXX-XXXX format.']
     1948>>> f.clean(None)
     1949u''
     1950>>> f.clean('')
     1951u''
     1952
     1953# CAProvinceField ################################################################
     1954
     1955CAProvinceField validates that the data is either an abbreviation or name of a
     1956Canadian province.
     1957>>> from django.contrib.localflavor.ca.forms import CAProvinceField
     1958>>> f = CAProvinceField()
     1959>>> f.clean('ab')
     1960u'AB'
     1961>>> f.clean('BC')
     1962u'BC'
     1963>>> f.clean('nova scotia')
     1964u'NS'
     1965>>> f.clean('  manitoba ')
     1966u'MB'
     1967>>> f.clean('T2S 2H7')
     1968Traceback (most recent call last):
     1969...
     1970ValidationError: [u'Enter a Canadian province or territory.']
     1971>>> f.clean(None)
     1972Traceback (most recent call last):
     1973...
     1974ValidationError: [u'This field is required.']
     1975>>> f.clean('')
     1976Traceback (most recent call last):
     1977...
     1978ValidationError: [u'This field is required.']
     1979
     1980>>> f = CAProvinceField(required=False)
     1981>>> f.clean('ab')
     1982u'AB'
     1983>>> f.clean('BC')
     1984u'BC'
     1985>>> f.clean('nova scotia')
     1986u'NS'
     1987>>> f.clean('  manitoba ')
     1988u'MB'
     1989>>> f.clean('T2S 2H7')
     1990Traceback (most recent call last):
     1991...
     1992ValidationError: [u'Enter a Canadian province or territory.']
     1993>>> f.clean(None)
     1994u''
     1995>>> f.clean('')
     1996u''
     1997
     1998# CAProvinceSelect ###############################################################
     1999
     2000CAProvinceSelect is a Select widget that uses a list of Canadian provinces/territories
     2001as its choices.
     2002>>> from django.contrib.localflavor.ca.forms import CAProvinceSelect
     2003>>> w = CAProvinceSelect()
     2004>>> print w.render('province', 'AB')
     2005<select name="province">
     2006<option value="AB" selected="selected">Alberta</option>
     2007<option value="BC">British Columbia</option>
     2008<option value="MB">Manitoba</option>
     2009<option value="NB">New Brunswick</option>
     2010<option value="NF">Newfoundland and Labrador</option>
     2011<option value="NT">Northwest Territories</option>
     2012<option value="NS">Nova Scotia</option>
     2013<option value="NU">Nunavut</option>
     2014<option value="ON">Ontario</option>
     2015<option value="PE">Prince Edward Island</option>
     2016<option value="QC">Quebec</option>
     2017<option value="SK">Saskatchewan</option>
     2018<option value="YK">Yukon</option>
     2019</select>
     2020
     2021# CASocialInsuranceNumberField #################################################
     2022>>> from django.contrib.localflavor.ca.forms import CASocialInsuranceNumberField
     2023>>> f = CASocialInsuranceNumberField()
     2024>>> f.clean('046-454-286')
     2025u'046-454-286'
     2026>>> f.clean('046-454-287')
     2027Traceback (most recent call last):
     2028...
     2029ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
     2030>>> f.clean('046 454 286')
     2031Traceback (most recent call last):
     2032...
     2033ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
     2034>>> f.clean('046-44-286')
     2035Traceback (most recent call last):
     2036...
     2037ValidationError: [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXXX format.']
     2038
    18212039"""
  • AUTHORS

     
    274274    Swaroop C H <http://www.swaroopch.info>
    275275    Aaron Swartz <http://www.aaronsw.com/>
    276276    Ville Säävuori <http://www.unessa.net/>
     277    Tyler Tarabula <tyler.tarabula@gmail.com>
    277278    Tyson Tate <tyson@fallingbullets.com>
    278279    Frank Tegtmeyer <fte@fte.to>
    279280    thebjorn <bp@datakortet.no>
Back to Top