1
0
mirror of https://github.com/django/django.git synced 2024-12-24 01:55:49 +00:00

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
This commit is contained in:
Alex Gaynor 2010-12-18 20:32:41 +00:00
parent f9e6ca1026
commit 8f012072af
3 changed files with 30 additions and 104 deletions

View File

@ -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 File

@ -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,

View File

@ -35,5 +35,6 @@ from regressiontests.forms.localflavortests import (
KWLocalFlavorTests,
NLLocalFlavorTests,
PLLocalFlavorTests,
PTLocalFlavorTests,
TRLocalFlavorTests,
)