def test_invalid(self): try: code = capostcode.validate("") self.fail('Invalid blank postal code not caught') except: pass try: code = capostcode.validate("no") self.fail('Invalid postal code "no" not caught') except: pass try: code = capostcode.validate("M5V M5V") self.fail('Invalid postal code "M5V M5V" not caught') except: pass try: code = capostcode.validate("D5V 2T6") self.fail('Invalid postal code "D5V 2T6" not caught -- "D" is not ' 'a valid major geographic area or province.') except: pass
def test_invalid(self): try: code = capostcode.validate("") self.fail('Invalid blank postal code not caught') except: pass try: code = capostcode.validate("no") self.fail('Invalid postal code "no" not caught') except: pass
def ca_postcode_validator(sender, postcode=None, country=None, **kwargs): if country.iso2_code == 'CA': from l10n.validators import capostcode try: pc = capostcode.validate(postcode) return pc except ValueError: raise forms.ValidationError('Please enter a valid Canadian postal code.')
def ca_postcode_validator(sender, postcode=None, country=None, **kwargs): if country.iso2_code == 'CA': from l10n.validators import capostcode try: pc = capostcode.validate(postcode) return pc except ValueError, ve: raise forms.ValidationError('Please enter a valid Canadian postal code.')
def test_valid(self): code = capostcode.validate("M5V2T6") self.assertEqual('M5V2T6', code) code = capostcode.validate("m5v2t6") self.assertEqual('M5V2T6', code)