From 41a1a89e4ede058f35f2ff6da18a828ac059d785 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 3 May 2011 11:52:04 +0000 Subject: Fixed #12595 -- Fixed bad arguments handling in localflavor form fields. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16146 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/localflavor/utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests/regressiontests/forms') diff --git a/tests/regressiontests/forms/localflavor/utils.py b/tests/regressiontests/forms/localflavor/utils.py index 482f7adeab..31d53dd255 100644 --- a/tests/regressiontests/forms/localflavor/utils.py +++ b/tests/regressiontests/forms/localflavor/utils.py @@ -1,5 +1,6 @@ from django.core.exceptions import ValidationError from django.core.validators import EMPTY_VALUES +from django.forms.fields import CharField from django.test.utils import get_warnings_state, restore_warnings_state from django.utils.unittest import TestCase @@ -13,8 +14,8 @@ class LocalFlavorTestCase(TestCase): def restore_warnings_state(self): restore_warnings_state(self._warnings_state) - def assertFieldOutput(self, fieldclass, valid, invalid, field_args=[], - field_kwargs={}, empty_value=u''): + def assertFieldOutput(self, fieldclass, valid, invalid, field_args=None, + field_kwargs=None, empty_value=u''): """ Asserts that a field behaves correctly with various inputs. @@ -29,6 +30,10 @@ class LocalFlavorTestCase(TestCase): empty_value: the expected clean output for inputs in EMPTY_VALUES """ + if field_args is None: + field_args = [] + if field_kwargs is None: + field_kwargs = {} required = fieldclass(*field_args, **field_kwargs) optional = fieldclass(*field_args, **dict(field_kwargs, required=False)) # test valid inputs @@ -49,3 +54,7 @@ class LocalFlavorTestCase(TestCase): self.assertRaisesRegexp(ValidationError, error_required, required.clean, e) self.assertEqual(optional.clean(e), empty_value) + # test that max_length and min_length are always accepted + if issubclass(fieldclass, CharField): + field_kwargs.update({'min_length':2, 'max_length':20}) + self.assertTrue(isinstance(fieldclass(*field_args, **field_kwargs), fieldclass)) -- cgit v1.3