Ticket #22943: validator_patch.diff
File validator_patch.diff, 6.2 KB (added by , 10 years ago) |
---|
-
django/core/validators.py
diff --git a/django/core/validators.py b/django/core/validators.py index 1e599ec..e33ab9e 100644
a b class EmailValidator(object): 181 181 182 182 validate_email = EmailValidator() 183 183 184 slug_re = r e.compile(r'^[-a-zA-Z0-9_]+$')184 slug_re = r'^[-a-zA-Z0-9_]+$' 185 185 validate_slug = RegexValidator(slug_re, _("Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."), 'invalid') 186 186 187 ipv4_re = r e.compile(r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$')187 ipv4_re = r'^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$' 188 188 validate_ipv4_address = RegexValidator(ipv4_re, _('Enter a valid IPv4 address.'), 'invalid') 189 189 190 190 … … def ip_address_validators(protocol, unpack_ipv4): 225 225 raise ValueError("The protocol '%s' is unknown. Supported: %s" 226 226 % (protocol, list(ip_address_validator_map))) 227 227 228 comma_separated_int_list_re = re.compile('^[\d,]+$')228 comma_separated_int_list_re = '^[\d,]+$' 229 229 validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _('Enter only digits separated by commas.'), 'invalid') 230 230 231 231 -
tests/validators/tests.py
diff --git a/tests/validators/tests.py b/tests/validators/tests.py index f586270..62984be 100644
a b from django.core.validators import ( 14 14 validate_ipv46_address, validate_ipv4_address, validate_ipv6_address, 15 15 validate_slug, 16 16 ) 17 from django.db.migrations.writer import MigrationWriter 17 18 from django.test.utils import str_prefix 18 19 19 20 … … class TestValidatorEquality(TestCase): 352 353 MinValueValidator(45), 353 354 MinValueValidator(11), 354 355 ) 356 357 358 class TestValidatorSerializability(TestCase): 359 """ 360 Tests that all built-in class-based validators are serializable and 361 thus usable in migrated apps (#22943). 362 363 Function-based validators are always deconstructible and don't have 364 to be worried about. 365 """ 366 def test_class_validator_serializability(self): 367 def test_serializability(validator, name): 368 try: 369 MigrationWriter.serialize(validator) 370 except ValueError: 371 self.fail(u"Serialization of %s failed" % name) 372 373 validators = [ 374 (EmailValidator(), 'EmailValidator'), 375 (MaxLengthValidator(20), 'MaxLengthValidator'), 376 (MaxValueValidator(20), 'MaxValueValidator'), 377 (MinLengthValidator(20), 'MinLengthValidator'), 378 (MinValueValidator(20), 'MinValueValidator'), 379 (RegexValidator(r'^\w+$'), 'RegexValidator'), 380 (URLValidator(), 'URLValidator'), 381 (validate_comma_separated_integer_list, 'validate_comma_separated_integer_list'), 382 (validate_email, 'validate_email'), 383 (validate_ipv4_address, 'validate_ipv4_address'), 384 (validate_slug, 'validate_slug') 385 ] 386 for validator, name in validators: 387 test_serializability(validator, name)