diff --git a/tests/regressiontests/forms/localflavor/pt.py b/tests/regressiontests/forms/localflavor/pt.py index 56d4d54c02..b8d784af19 100644 --- a/tests/regressiontests/forms/localflavor/pt.py +++ b/tests/regressiontests/forms/localflavor/pt.py @@ -1,106 +1,32 @@ -# -*- coding: utf-8 -*- -# Tests for the contrib/localflavor/ PT form fields. +from django.contrib.localflavor.pt.forms import PTZipCodeField, PTPhoneNumberField -tests = r""" -# PTZipCodeField ############################################################# +from utils import LocalFlavorTestCase -PTZipCodeField validates that the data is a valid PT zipcode. ->>> from django.contrib.localflavor.pt.forms import PTZipCodeField ->>> f = PTZipCodeField() ->>> f.clean('3030-034') -u'3030-034' ->>> f.clean('1003456') -u'1003-456' ->>> f.clean('2A200') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX-XXX.'] ->>> f.clean('980001') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX-XXX.'] ->>> f.clean(None) -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f.clean('') -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f = PTZipCodeField(required=False) ->>> f.clean('3030-034') -u'3030-034' ->>> f.clean('1003456') -u'1003-456' ->>> f.clean('2A200') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX-XXX.'] ->>> f.clean('980001') -Traceback (most recent call last): -... -ValidationError: [u'Enter a zip code in the format XXXX-XXX.'] ->>> f.clean(None) -u'' ->>> f.clean('') -u'' +class PTLocalFlavorTests(LocalFlavorTestCase): + def test_PTZipCodeField(self): + error_format = [u'Enter a zip code in the format XXXX-XXX.'] + valid = { + '3030-034': '3030-034', + '1003456': '1003-456', + } + invalid = { + '2A200': error_format, + '980001': error_format, + } + self.assertFieldOutput(PTZipCodeField, valid, invalid) -# PTPhoneNumberField ########################################################## - -PTPhoneNumberField validates that the data is a valid Portuguese phone number. -It's normalized to XXXXXXXXX format or +X(X) for international numbers. Dots are valid too. ->>> from django.contrib.localflavor.pt.forms import PTPhoneNumberField ->>> f = PTPhoneNumberField() ->>> f.clean('917845189') -u'917845189' ->>> f.clean('91 784 5189') -u'917845189' ->>> f.clean('91 784 5189') -u'917845189' ->>> f.clean('+351 91 111') -u'+35191111' ->>> f.clean('00351873') -u'00351873' ->>> f.clean('91 784 51 8') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.'] ->>> f.clean('091 456 987 1') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.'] ->>> f.clean(None) -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] ->>> f.clean('') -Traceback (most recent call last): -... -ValidationError: [u'This field is required.'] - ->>> f = PTPhoneNumberField(required=False) ->>> f.clean('917845189') -u'917845189' ->>> f.clean('91 784 5189') -u'917845189' ->>> f.clean('91 784 5189') -u'917845189' ->>> f.clean('+351 91 111') -u'+35191111' ->>> f.clean('00351873') -u'00351873' ->>> f.clean('91 784 51 8') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.'] ->>> f.clean('091 456 987 1') -Traceback (most recent call last): -... -ValidationError: [u'Phone numbers must have 9 digits, or start by + or 00.'] ->>> f.clean(None) -u'' ->>> f.clean('') -u'' - -""" + def test_PTPhoneNumberField(self): + error_format = [u'Phone numbers must have 9 digits, or start by + or 00.'] + valid = { + '917845189': '917845189', + '91 784 5189': '917845189', + '91 784 5189': '917845189', + '+351 91 111': '+35191111', + '00351873': '00351873', + } + invalid = { + '91 784 51 8': error_format, + '091 456 987 1': error_format, + } + self.assertFieldOutput(PTPhoneNumberField, valid, invalid) diff --git a/tests/regressiontests/forms/localflavortests.py b/tests/regressiontests/forms/localflavortests.py index 20fca92ea0..3c7bc1ef7b 100644 --- a/tests/regressiontests/forms/localflavortests.py +++ b/tests/regressiontests/forms/localflavortests.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- from localflavor.cz import tests as localflavor_cz_tests -from localflavor.pt import tests as localflavor_pt_tests from localflavor.ro import tests as localflavor_ro_tests from localflavor.se import tests as localflavor_se_tests from localflavor.sk import tests as localflavor_sk_tests @@ -30,11 +29,11 @@ from localflavor.jp import JPLocalFlavorTests from localflavor.kw import KWLocalFlavorTests from localflavor.nl import NLLocalFlavorTests from localflavor.pl import PLLocalFlavorTests +from localflavor.pt import PTLocalFlavorTests __test__ = { 'localflavor_cz_tests': localflavor_cz_tests, - 'localflavor_pt_tests': localflavor_pt_tests, 'localflavor_ro_tests': localflavor_ro_tests, 'localflavor_se_tests': localflavor_se_tests, 'localflavor_sk_tests': localflavor_sk_tests, diff --git a/tests/regressiontests/forms/tests/__init__.py b/tests/regressiontests/forms/tests/__init__.py index c878a2a1c8..b1588d85e9 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -33,4 +33,5 @@ from regressiontests.forms.localflavortests import ( KWLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, + PTLocalFlavorTests, )