From 8f012072afb2d4ec25cddab29cf0b9ef605bf138 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 18 Dec 2010 20:32:41 +0000 Subject: [PATCH] Converted Portuguese localflavor doctests into unittests. We have always been at war with doctests. Thanks to Idan Gazit. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14950 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor/pt.py | 130 ++++-------------- .../regressiontests/forms/localflavortests.py | 3 +- tests/regressiontests/forms/tests/__init__.py | 1 + 3 files changed, 30 insertions(+), 104 deletions(-) diff --git a/tests/regressiontests/forms/localflavor/pt.py b/tests/regressiontests/forms/localflavor/pt.py index 56d4d54c02c..ce520182776 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 5c54c43a851..c6a050edc84 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 @@ -31,12 +30,12 @@ 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 from localflavor.tr import TRLocalFlavorTests __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 b458b4a6b0d..124646cbb1e 100644 --- a/tests/regressiontests/forms/tests/__init__.py +++ b/tests/regressiontests/forms/tests/__init__.py @@ -35,5 +35,6 @@ from regressiontests.forms.localflavortests import ( KWLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, + PTLocalFlavorTests, TRLocalFlavorTests, )