kopia lustrzana https://github.com/wagtail/wagtail
opps forgot files
rodzic
9f12c109be
commit
da7b96cca6
|
@ -0,0 +1,14 @@
|
|||
from django.test import TestCase
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from wagtail.wagtailcore.validators import validate_not_whitespace
|
||||
|
||||
|
||||
class TestValidators(TestCase):
|
||||
|
||||
def test_not_whitespace(self):
|
||||
validate_not_whitespace('bar')
|
||||
|
||||
for test_value in (' ', '\t', '\r', '\n', '\r\n'):
|
||||
with self.assertRaises(ValidationError):
|
||||
validate_not_whitespace(test_value)
|
|
@ -0,0 +1,15 @@
|
|||
import re
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
WHITESPACE_RE = re.compile(r'^\s+$')
|
||||
|
||||
|
||||
def validate_not_whitespace(value):
|
||||
"""
|
||||
Validate that a value isn't all whitespace, for example in title and
|
||||
seo_title
|
||||
"""
|
||||
if value and WHITESPACE_RE.match(value):
|
||||
raise ValidationError(_('Value cannot be entirely whitespace characters'))
|
Ładowanie…
Reference in New Issue