Fixed #14593 -- change this warning to be a PendingDeprecationWarning. Also converted the Czech localflavor tests to be unittests. We have always been at war with doctests. Thanks to Idan Gazit.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15062 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-12-27 07:41:26 +00:00
parent 38d60c3941
commit c00c377e54
5 changed files with 118 additions and 158 deletions

View File

@ -73,7 +73,7 @@ class CZBirthNumberField(Field):
import warnings import warnings
warnings.warn( warnings.warn(
"Support for validating the gender of a CZ Birth number has been deprecated.", "Support for validating the gender of a CZ Birth number has been deprecated.",
DeprecationWarning) PendingDeprecationWarning)
if gender == 'f': if gender == 'f':
female_const = 50 female_const = 50
elif gender == 'm': elif gender == 'm':

View File

@ -539,3 +539,11 @@ GeoDjango
to indicate possible faulty application code. A warning is now raised to indicate possible faulty application code. A warning is now raised
if :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` is called when if :meth:`~django.contrib.gis.geos.GEOSGeometry.transform` is called when
the SRID of the geometry is less than 0 or ``None``. the SRID of the geometry is less than 0 or ``None``.
``CZBirthNumberField.clean``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previously this field's ``clean()`` method accepted a second, gender, argument
which allowed stronger validation checks to be made, however since this
argument could never actually be passed from the Django form machinery it is
now pending deprecation.

View File

@ -1,126 +1,105 @@
# -*- coding: utf-8 -*- import warnings
# Tests for the contrib/localflavor/ CZ Form Fields
tests = r""" from django.contrib.localflavor.cz.forms import (CZPostalCodeField,
# CZPostalCodeField ######################################################### CZRegionSelect, CZBirthNumberField, CZICNumberField)
>>> from django.contrib.localflavor.cz.forms import CZPostalCodeField from django.core.exceptions import ValidationError
>>> f = CZPostalCodeField() from utils import LocalFlavorTestCase
>>> f.clean('84545x')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('91909')
u'91909'
>>> f.clean('917 01')
u'91701'
>>> f.clean('12345')
u'12345'
>>> f.clean('123456')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('1234')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
>>> f.clean('123 4')
Traceback (most recent call last):
...
ValidationError: [u'Enter a postal code in the format XXXXX or XXX XX.']
# CZRegionSelect ############################################################
>>> from django.contrib.localflavor.cz.forms import CZRegionSelect class CZLocalFlavorTests(LocalFlavorTestCase):
>>> w = CZRegionSelect() def setUp(self):
>>> w.render('regions', 'TT') self.save_warnings_state()
u'<select name="regions">\n<option value="PR">Prague</option>\n<option value="CE">Central Bohemian Region</option>\n<option value="SO">South Bohemian Region</option>\n<option value="PI">Pilsen Region</option>\n<option value="CA">Carlsbad Region</option>\n<option value="US">Usti Region</option>\n<option value="LB">Liberec Region</option>\n<option value="HK">Hradec Region</option>\n<option value="PA">Pardubice Region</option>\n<option value="VY">Vysocina Region</option>\n<option value="SM">South Moravian Region</option>\n<option value="OL">Olomouc Region</option>\n<option value="ZL">Zlin Region</option>\n<option value="MS">Moravian-Silesian Region</option>\n</select>' warnings.filterwarnings(
"ignore",
category=PendingDeprecationWarning,
module='django.contrib.localflavor.cz.forms'
)
# CZBirthNumberField ######################################################## def tearDown(self):
self.restore_warnings_state()
>>> from django.contrib.localflavor.cz.forms import CZBirthNumberField def test_CZRegionSelect(self):
>>> f = CZBirthNumberField() f = CZRegionSelect()
>>> f.clean('880523/1237') out = u'''<select name="regions">
u'880523/1237' <option value="PR">Prague</option>
>>> f.clean('8805231237') <option value="CE">Central Bohemian Region</option>
u'8805231237' <option value="SO">South Bohemian Region</option>
>>> f.clean('880523/000') <option value="PI">Pilsen Region</option>
u'880523/000' <option value="CA">Carlsbad Region</option>
>>> f.clean('880523000') <option value="US">Usti Region</option>
u'880523000' <option value="LB">Liberec Region</option>
>>> f.clean('882101/0011') <option value="HK">Hradec Region</option>
u'882101/0011' <option value="PA">Pardubice Region</option>
>>> f.clean('880523/1237', 'm') <option value="VY">Vysocina Region</option>
u'880523/1237' <option value="SM">South Moravian Region</option>
>>> f.clean('885523/1231', 'f') <option value="OL">Olomouc Region</option>
u'885523/1231' <option value="ZL">Zlin Region</option>
>>> f.clean('123456/12') <option value="MS">Moravian-Silesian Region</option>
Traceback (most recent call last): </select>'''
... self.assertEqual(f.render('regions', 'TT'), out)
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('123456/12345')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('12345612')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('12345612345')
Traceback (most recent call last):
...
ValidationError: [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('881523/0000', 'm')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('885223/0000', 'm')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('881223/0000', 'f')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('886523/0000', 'f')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('880523/1239')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('8805231239')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
>>> f.clean('990101/0011')
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid birth number.']
# CZICNumberField ######################################################## def test_CZPostalCodeField(self):
error_format = [u'Enter a postal code in the format XXXXX or XXX XX.']
valid = {
'91909': '91909',
'917 01': '91701',
'12345': '12345',
}
invalid = {
'84545x': error_format,
'123456': error_format,
'1234': error_format,
'123 4': error_format,
}
self.assertFieldOutput(CZPostalCodeField, valid, invalid)
>>> from django.contrib.localflavor.cz.forms import CZICNumberField def test_CZBirthNumberField(self):
>>> f = CZICNumberField() error_format = [u'Enter a birth number in the format XXXXXX/XXXX or XXXXXXXXXX.']
>>> f.clean('12345679') error_invalid = [u'Enter a valid birth number.']
u'12345679' valid = {
>>> f.clean('12345601') '880523/1237': '880523/1237',
u'12345601' '8805231237': '8805231237',
>>> f.clean('12345661') '880523/000': '880523/000',
u'12345661' '880523000': '880523000',
>>> f.clean('12345610') '882101/0011': '882101/0011',
u'12345610' }
>>> f.clean('1234567') invalid = {
Traceback (most recent call last): '123456/12': error_format,
... '123456/12345': error_format,
ValidationError: [u'Enter a valid IC number.'] '12345612': error_format,
>>> f.clean('12345660') '12345612345': error_format,
Traceback (most recent call last): '880523/1239': error_invalid,
... '8805231239': error_invalid,
ValidationError: [u'Enter a valid IC number.'] '990101/0011': error_invalid,
>>> f.clean('12345600') }
Traceback (most recent call last): self.assertFieldOutput(CZBirthNumberField, valid, invalid)
...
ValidationError: [u'Enter a valid IC number.'] # These tests should go away in 1.4.
""" # http://code.djangoproject.com/ticket/14593
f = CZBirthNumberField()
self.assertEqual(f.clean('880523/1237', 'm'), '880523/1237'),
self.assertEqual(f.clean('885523/1231', 'f'), '885523/1231')
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
f.clean, '881523/0000', 'm')
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
f.clean, '885223/0000', 'm')
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
f.clean, '881523/0000', 'f')
self.assertRaisesRegexp(ValidationError, unicode(error_invalid),
f.clean, '885223/0000', 'f')
def test_CZICNumberField(self):
error_invalid = [u'Enter a valid IC number.']
valid ={
'12345679': '12345679',
'12345601': '12345601',
'12345661': '12345661',
'12345610': '12345610',
}
invalid = {
'1234567': error_invalid,
'12345660': error_invalid,
'12345600': error_invalid,
}
self.assertFieldOutput(CZICNumberField, valid, invalid)

View File

@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from localflavor.cz import tests as localflavor_cz_tests
from localflavor.ar import ARLocalFlavorTests from localflavor.ar import ARLocalFlavorTests
from localflavor.at import ATLocalFlavorTests from localflavor.at import ATLocalFlavorTests
from localflavor.au import AULocalFlavorTests from localflavor.au import AULocalFlavorTests
@ -9,6 +6,7 @@ from localflavor.br import BRLocalFlavorTests
from localflavor.ca import CALocalFlavorTests from localflavor.ca import CALocalFlavorTests
from localflavor.ch import CHLocalFlavorTests from localflavor.ch import CHLocalFlavorTests
from localflavor.cl import CLLocalFlavorTests from localflavor.cl import CLLocalFlavorTests
from localflavor.cz import CZLocalFlavorTests
from localflavor.de import DELocalFlavorTests from localflavor.de import DELocalFlavorTests
from localflavor.es import ESLocalFlavorTests from localflavor.es import ESLocalFlavorTests
from localflavor.fi import FILocalFlavorTests from localflavor.fi import FILocalFlavorTests
@ -33,7 +31,3 @@ from localflavor.us import USLocalFlavorTests
from localflavor.uy import UYLocalFlavorTests from localflavor.uy import UYLocalFlavorTests
from localflavor.za import ZALocalFlavorTests from localflavor.za import ZALocalFlavorTests
__test__ = {
'localflavor_cz_tests': localflavor_cz_tests,
}

View File

@ -12,36 +12,15 @@ from validators import TestFieldWithValidators
from widgets import * from widgets import *
from regressiontests.forms.localflavortests import ( from regressiontests.forms.localflavortests import (
__test__, ARLocalFlavorTests, ATLocalFlavorTests, AULocalFlavorTests,
ARLocalFlavorTests, BELocalFlavorTests, BRLocalFlavorTests, CALocalFlavorTests,
ATLocalFlavorTests, CHLocalFlavorTests, CLLocalFlavorTests, CZLocalFlavorTests,
AULocalFlavorTests, DELocalFlavorTests, ESLocalFlavorTests, FILocalFlavorTests,
BELocalFlavorTests, FRLocalFlavorTests, GenericLocalFlavorTests, IDLocalFlavorTests,
BRLocalFlavorTests, IELocalFlavorTests, ILLocalFlavorTests, ISLocalFlavorTests,
CALocalFlavorTests, ITLocalFlavorTests, JPLocalFlavorTests, KWLocalFlavorTests,
CHLocalFlavorTests, NLLocalFlavorTests, PLLocalFlavorTests, PTLocalFlavorTests,
CLLocalFlavorTests, ROLocalFlavorTests, SELocalFlavorTests, SKLocalFlavorTests,
DELocalFlavorTests, TRLocalFlavorTests, UKLocalFlavorTests, USLocalFlavorTests,
ESLocalFlavorTests, UYLocalFlavorTests, ZALocalFlavorTests
FILocalFlavorTests,
FRLocalFlavorTests,
GenericLocalFlavorTests,
IDLocalFlavorTests,
IELocalFlavorTests,
ILLocalFlavorTests,
ISLocalFlavorTests,
ITLocalFlavorTests,
JPLocalFlavorTests,
KWLocalFlavorTests,
NLLocalFlavorTests,
PLLocalFlavorTests,
PTLocalFlavorTests,
ROLocalFlavorTests,
SELocalFlavorTests,
SKLocalFlavorTests,
TRLocalFlavorTests,
UKLocalFlavorTests,
USLocalFlavorTests,
UYLocalFlavorTests,
ZALocalFlavorTests,
) )