summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDejan Noveski <dr.mote@gmail.com>2014-03-13 12:23:12 +0100
committerErik Romijn <erik@erik.io>2014-03-21 11:12:36 +0100
commit4d0c5f61427a8e67552ee2d777fffbadc7aff3b2 (patch)
tree3a2c5393dbad0163f947cc2944e1f71f27ffd1a1 /tests
parentf2eea960e052db2d280e6dd016b0f8f23d5a8ef7 (diff)
Fixed #22255 -- Added support for specifying re flags in RegexValidator
Diffstat (limited to 'tests')
-rw-r--r--tests/forms_tests/tests/test_validators.py15
-rw-r--r--tests/validators/tests.py12
2 files changed, 26 insertions, 1 deletions
diff --git a/tests/forms_tests/tests/test_validators.py b/tests/forms_tests/tests/test_validators.py
index bd098d150a..c69597b497 100644
--- a/tests/forms_tests/tests/test_validators.py
+++ b/tests/forms_tests/tests/test_validators.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import re
from unittest import TestCase
from django import forms
@@ -24,11 +25,22 @@ class UserForm(forms.Form):
)
]
)
+ ignore_case_string = forms.CharField(
+ max_length=50,
+ validators=[
+ validators.RegexValidator(
+ regex='^[a-z]*$',
+ message="Letters only.",
+ flags=re.IGNORECASE,
+ )
+ ]
+
+ )
class TestFieldWithValidators(TestCase):
def test_all_errors_get_reported(self):
- form = UserForm({'full_name': 'not int nor mail', 'string': '2 is not correct'})
+ form = UserForm({'full_name': 'not int nor mail', 'string': '2 is not correct', 'ignore_case_string': "IgnORE Case strIng"})
self.assertRaises(ValidationError, form.fields['full_name'].clean, 'not int nor mail')
try:
@@ -38,3 +50,4 @@ class TestFieldWithValidators(TestCase):
self.assertFalse(form.is_valid())
self.assertEqual(form.errors['string'], ["Letters only."])
+ self.assertEqual(form.errors['string'], ["Letters only."])
diff --git a/tests/validators/tests.py b/tests/validators/tests.py
index b88d71fa68..25f1e1b2f2 100644
--- a/tests/validators/tests.py
+++ b/tests/validators/tests.py
@@ -198,6 +198,10 @@ TEST_DATA = (
(RegexValidator(re.compile('x'), inverse_match=True), 'y', None),
(RegexValidator('x', inverse_match=True), 'x', ValidationError),
(RegexValidator(re.compile('x'), inverse_match=True), 'x', ValidationError),
+
+ (RegexValidator('x', flags=re.IGNORECASE), 'y', ValidationError),
+ (RegexValidator('a'), 'A', ValidationError),
+ (RegexValidator('a', flags=re.IGNORECASE), 'A', None),
)
@@ -250,6 +254,14 @@ class TestSimpleValidators(TestCase):
self.assertEqual(str(v), str_prefix("{%(_)s'first': [%(_)s'First Problem']}"))
self.assertEqual(repr(v), str_prefix("ValidationError({%(_)s'first': [%(_)s'First Problem']})"))
+ def test_regex_validator_flags(self):
+ try:
+ RegexValidator(re.compile('a'), flags=re.IGNORECASE)
+ except TypeError:
+ pass
+ else:
+ self.fail("TypeError not raised when flags and pre-compiled regex in RegexValidator")
+
test_counter = 0
for validator, value, expected in TEST_DATA:
name, method = create_simple_test_method(validator, expected, value, test_counter)