PageRenderTime 101ms CodeModel.GetById 61ms app.highlight 8ms RepoModel.GetById 12ms app.codeStats 0ms

/tests/regressiontests/forms/localflavor/ca.py

https://code.google.com/p/mango-py/
Python | 108 lines | 102 code | 6 blank | 0 comment | 4 complexity | 8875d1b75260bcae41b5200148ec9fc0 MD5 | raw file
  1import warnings
  2
  3from django.contrib.localflavor.ca.forms import (CAPostalCodeField,
  4        CAPhoneNumberField, CAProvinceField, CAProvinceSelect,
  5        CASocialInsuranceNumberField)
  6
  7from utils import LocalFlavorTestCase
  8
  9
 10class CALocalFlavorTests(LocalFlavorTestCase):
 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'
 17        )
 18
 19    def tearDown(self):
 20        self.restore_warnings_state()
 21
 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.assertEqual(f.render('province', 'AB'), out)
 40
 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
 49        }
 50        invalid = {
 51            'T2S2H7' : error_format,
 52            'T2S 2H' : error_format,
 53            '2T6 H8I': error_format,
 54            'T2S2H' : error_format,
 55            90210 : error_format,
 56            'W2S 2H3': error_format,
 57            'Z2S 2H3': error_format,
 58            'F2S 2H3': error_format,
 59            'A2S 2D3': error_format,
 60            'A2I 2R3': error_format,
 61            'A2Q 2R3': error_format,
 62            'U2B 2R3': error_format,
 63            'O2B 2R3': error_format,
 64        }
 65        self.assertFieldOutput(CAPostalCodeField, valid, invalid)
 66
 67    def test_CAPhoneNumberField(self):
 68        error_format = [u'Phone numbers must be in XXX-XXX-XXXX format.']
 69        valid = {
 70            '403-555-1212': '403-555-1212',
 71            '4035551212': '403-555-1212',
 72            '403 555-1212': '403-555-1212',
 73            '(403) 555-1212': '403-555-1212',
 74            '403 555 1212': '403-555-1212',
 75            '403.555.1212': '403-555-1212',
 76            '403.555-1212': '403-555-1212',
 77            ' (403) 555.1212 ': '403-555-1212',
 78        }
 79        invalid = {
 80           '555-1212': error_format,
 81           '403-55-1212': error_format,
 82        }
 83        self.assertFieldOutput(CAPhoneNumberField, valid, invalid)
 84
 85    def test_CAProvinceField(self):
 86        error_format = [u'Enter a Canadian province or territory.']
 87        valid = {
 88            'ab': 'AB',
 89            'BC': 'BC',
 90            'nova scotia': 'NS',
 91            '  manitoba ': 'MB',
 92        }
 93        invalid = {
 94            'T2S 2H7': error_format,
 95        }
 96        self.assertFieldOutput(CAProvinceField, valid, invalid)
 97
 98    def test_CASocialInsuranceField(self):
 99        error_format = [u'Enter a valid Canadian Social Insurance number in XXX-XXX-XXX format.']
100        valid = {
101            '046-454-286': '046-454-286',
102        }
103        invalid = {
104            '046-454-287': error_format,
105            '046 454 286': error_format,
106            '046-44-286': error_format,
107        }
108        self.assertFieldOutput(CASocialInsuranceNumberField, valid, invalid)