summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-07-05 13:29:08 +0000
committerHonza Král <honza.kral@gmail.com>2009-07-05 13:29:08 +0000
commitc1093ca87fbcb57c47aeb323edacfadead859cb2 (patch)
tree0943a471514380216ecc3c69e0129745eeb9d94d /tests
parentcb7d3f2a0e16c974f84df8b62d24a774220f7507 (diff)
[soc2009/model-validation] SlugField and IPAddressField now use validators.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11191 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/validators/tests.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py
index 7f84475149..e19353d03b 100644
--- a/tests/modeltests/validators/tests.py
+++ b/tests/modeltests/validators/tests.py
@@ -1,7 +1,11 @@
+# -*- coding: utf-8 -*-
from unittest import TestCase
from django.core.exceptions import ValidationError
-from django.core.validators import validate_integer, validate_email, RequiredIfOtherFieldBlank
+from django.core.validators import (
+ validate_integer, validate_email, RequiredIfOtherFieldBlank,
+ validate_slug, validate_ipv4_address
+ )
class TestSimpleValidators(TestCase):
pass
@@ -12,15 +16,42 @@ SIMPLE_VALIDATORS_VALUES = (
(validate_integer, '-42', None),
(validate_integer, -42, None),
(validate_integer, -42.5, None),
+
(validate_integer, None, ValidationError),
(validate_integer, 'a', ValidationError),
+
+
(validate_email, 'email@here.com', None),
(validate_email, 'weirder-email@here.and.there.com', None),
+
(validate_email, None, ValidationError),
(validate_email, '', ValidationError),
(validate_email, 'abc', ValidationError),
(validate_email, 'a @x.cz', ValidationError),
(validate_email, 'something@@somewhere.com', ValidationError),
+
+
+ (validate_slug, 'slug-ok', None),
+ (validate_slug, 'longer-slug-still-ok', None),
+ (validate_slug, '--------', None),
+ (validate_slug, 'nohyphensoranything', None),
+
+ (validate_slug, '', ValidationError),
+ (validate_slug, ' text ', ValidationError),
+ (validate_slug, ' ', ValidationError),
+ (validate_slug, 'some@mail.com', ValidationError),
+ (validate_slug, '你好', ValidationError),
+ (validate_slug, '\n', ValidationError),
+
+
+ (validate_ipv4_address, '1.1.1.1', None),
+ (validate_ipv4_address, '255.0.0.0', None),
+ (validate_ipv4_address, '0.0.0.0', None),
+
+ (validate_ipv4_address, '256.1.1.1', ValidationError),
+ (validate_ipv4_address, '25.1.1.', ValidationError),
+ (validate_ipv4_address, '25,1,1,1', ValidationError),
+ (validate_ipv4_address, '25.1 .1.1', ValidationError),
)
def get_simple_test_func(validator, expected, value, num):