1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Began converting localflavor doctests into unittests, starting with the German ones. Also introduced a new base class to facilitate ease of testing form fields. We have always been at war with doctests. Thanks to Idan Gazit for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14626 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2010-11-19 19:33:07 +00:00
parent 59c84b4391
commit a3e7ee7c40
4 changed files with 85 additions and 38 deletions

View File

@@ -0,0 +1,38 @@
from django.core.exceptions import ValidationError
from django.core.validators import EMPTY_VALUES
from django.utils.unittest import TestCase
class LocalFlavorTestCase(TestCase):
def assertFieldOutput(self, fieldclass, valid, invalid):
"""Asserts that a field behaves correctly with various inputs.
Args:
fieldclass: the class of the field to be tested.
valid: a dictionary mapping valid inputs to their expected
cleaned values.
invalid: a dictionary mapping invalid inputs to one or more
raised error messages.
"""
required = fieldclass()
optional = fieldclass(required=False)
# test valid inputs
for input, output in valid.items():
self.assertEqual(required.clean(input), output)
self.assertEqual(optional.clean(input), output)
# test invalid inputs
for input, errors in invalid.items():
self.assertRaisesRegexp(ValidationError, unicode(errors),
required.clean, input
)
self.assertRaisesRegexp(ValidationError, unicode(errors),
optional.clean, input
)
# test required inputs
error_required = u'This field is required'
for e in EMPTY_VALUES:
self.assertRaisesRegexp(ValidationError, error_required,
required.clean, e
)
self.assertEqual(optional.clean(e), u'')