Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Converted Portuguese localflavor doctests into unittests. We …

…have always been at war with doctests. Thanks to Idan Gazit. Backport of [14950].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14974 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b6fbf30a3211986a75e15aa93b4e21b590eb5a1e 1 parent 4b3198d
@alex alex authored
View
130 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)
View
3  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.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,
View
1  tests/regressiontests/forms/tests/__init__.py
@@ -33,4 +33,5 @@
KWLocalFlavorTests,
NLLocalFlavorTests,
PLLocalFlavorTests,
+ PTLocalFlavorTests,
)
Please sign in to comment.
Something went wrong with that request. Please try again.