Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #14750 -- ILPostalCodeField didn't handle all EMPTY_VALUES corr…

…ectly. Also converted the Israeli localflavor testcases to use the new, less verbose format. Thanks to Idan Gazit.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14943 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6a362d368411052ca8d3f0058d82b657eae846f5 1 parent b5ac695
Alex Gaynor alex authored
3  django/contrib/localflavor/il/forms.py
View
@@ -4,6 +4,7 @@
import re
from django.core.exceptions import ValidationError
+from django.core.validators import EMPTY_VALUES
from django.forms.fields import RegexField, Field, EMPTY_VALUES
from django.utils.checksums import luhn
from django.utils.translation import ugettext_lazy as _
@@ -34,7 +35,7 @@ def __init__(self, *args, **kwargs):
super(ILPostalCodeField, self).__init__(r'^\d{5}$', *args, **kwargs)
def clean(self, value):
- if value is not None:
+ if value not in EMPTY_VALUES:
value = value.replace(" ", "")
return super(ILPostalCodeField, self).clean(value)
86 tests/regressiontests/forms/localflavor/il.py
View
@@ -1,57 +1,39 @@
from django.contrib.localflavor.il.forms import (ILPostalCodeField,
ILIDNumberField)
-from django.core.exceptions import ValidationError
-from django.utils.unittest import TestCase
+from utils import LocalFlavorTestCase
-class ILLocalFlavorTests(TestCase):
- def test_postal_code_field(self):
- f = ILPostalCodeField()
- self.assertRaisesRegexp(ValidationError,
- "Enter a postal code in the format XXXXX",
- f.clean, "84545x"
- )
- self.assertEqual(f.clean("69973"), "69973")
- self.assertEqual(f.clean("699 73"), "69973")
- self.assertEqual(f.clean("12345"), "12345")
- self.assertRaisesRegexp(ValidationError,
- "Enter a postal code in the format XXXXX",
- f.clean, "123456"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a postal code in the format XXXXX",
- f.clean, "1234"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a postal code in the format XXXXX",
- f.clean, "123 4"
- )
- self.assertRaises(ValidationError, f.clean, None)
- def test_id_number_field(self):
- f = ILIDNumberField()
- self.assertEqual(f.clean("3933742-3"), "39337423")
- self.assertEqual(f.clean("39337423"), "39337423")
- self.assertEqual(f.clean("039337423"), "039337423")
- self.assertEqual(f.clean("03933742-3"), "039337423")
- self.assertEqual(f.clean("0091"), "0091")
- self.assertRaisesRegexp(ValidationError,
- "Enter a valid ID number.",
- f.clean, "123456789"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a valid ID number.",
- f.clean, "12345678-9"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a valid ID number.",
- f.clean, "012346578"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a valid ID number.",
- f.clean, "012346578-"
- )
- self.assertRaisesRegexp(ValidationError,
- "Enter a valid ID number.",
- f.clean, "0001"
- )
+class ILLocalFlavorTests(LocalFlavorTestCase):
+ def test_ILPostalCodeField(self):
+ error_format = [u'Enter a postal code in the format XXXXX']
+ valid = {
+ '69973': '69973',
+ '699 73': '69973',
+ '12345': '12345',
+ }
+ invalid = {
+ '84545x': error_format,
+ '123456': error_format,
+ '1234': error_format,
+ '123 4': error_format,
+ }
+ self.assertFieldOutput(ILPostalCodeField, valid, invalid)
+
+ def test_ILIDNumberField(self):
+ error_invalid = [u'Enter a valid ID number.']
+ valid = {
+ '3933742-3': '39337423',
+ '39337423': '39337423',
+ '039337423': '039337423',
+ '03933742-3': '039337423',
+ '0091': '0091',
+ }
+ invalid = {
+ '123456789': error_invalid,
+ '12345678-9': error_invalid,
+ '012346578': error_invalid,
+ '012346578-': error_invalid,
+ '0001': error_invalid,
+ }
+ self.assertFieldOutput(ILIDNumberField, valid, invalid)
Please sign in to comment.
Something went wrong with that request. Please try again.