mirror of
https://github.com/django/django.git
synced 2025-08-18 17:50:58 +00:00
[1.7.x] Fixed #22255 -- Added support for specifying re flags in RegexValidator
Backport of 4d0c5f6142
from master.
This commit is contained in:
parent
cc8a800d0c
commit
b74ec85c1d
5 changed files with 61 additions and 8 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue