summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-08-15 13:35:43 +0000
committerHonza Král <honza.kral@gmail.com>2009-08-15 13:35:43 +0000
commitf20e7fcdd22fe3a2181071af1f8460bb6c3d32f0 (patch)
tree1a917eca6c2c74ae8373e05ee89890e0b7de8dec /tests
parent7a6a71dd0c6e04d46c0db55a46d97585e7edfe45 (diff)
[soc2009/model-validation] simple test for URLValidator, RegexValidator and BaseValidator
URL tests copied from tests/regressiontests/forms/fields.py git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11460 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/validators/tests.py38
1 files changed, 36 insertions, 2 deletions
diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py
index 3e185d1fc6..de4d94f1af 100644
--- a/tests/modeltests/validators/tests.py
+++ b/tests/modeltests/validators/tests.py
@@ -2,14 +2,16 @@
import types
from unittest import TestCase
from datetime import datetime, timedelta
+import re
from django.core.exceptions import ValidationError
from django.core.validators import (
validate_integer, validate_email, validate_slug, validate_ipv4_address,
validate_comma_separated_integer_list, MaxValueValidator,
MinValueValidator, MaxLengthValidator, MinLengthValidator,
- RequiredIfOtherFieldBlank,
- )
+ RequiredIfOtherFieldBlank, URLValidator, BaseValidator,
+ RegexValidator,
+)
now = datetime.now()
class TestSimpleValidators(TestCase):
@@ -94,8 +96,40 @@ SIMPLE_VALIDATORS_VALUES = (
(MinLengthValidator(10), '', ValidationError),
+ (URLValidator(), 'http://www.djangoproject.com/', None),
+ (URLValidator(), 'http://localhost/', None),
+ (URLValidator(), 'http://example.com/', None),
+ (URLValidator(), 'http://www.example.com/', None),
+ (URLValidator(), 'http://www.example.com:8000/test', None),
+ (URLValidator(), 'http://valid-with-hyphens.com/', None),
+ (URLValidator(), 'http://subdomain.domain.com/', None),
+ (URLValidator(), 'http://200.8.9.10/', None),
+ (URLValidator(), 'http://200.8.9.10:8000/test', None),
+ (URLValidator(), 'http://valid-----hyphens.com/', None),
+
+ (URLValidator(), 'foo', ValidationError),
+ (URLValidator(), 'http://', ValidationError),
+ (URLValidator(), 'http://example', ValidationError),
+ (URLValidator(), 'http://example.', ValidationError),
+ (URLValidator(), 'http://.com', ValidationError),
+ (URLValidator(), 'http://invalid-.com', ValidationError),
+ (URLValidator(), 'http://-invalid.com', ValidationError),
+ (URLValidator(), 'http://inv-.alid-.com', ValidationError),
+ (URLValidator(), 'http://inv-.-alid.com', ValidationError),
+
+ (BaseValidator(True), True, None),
+ (BaseValidator(True), False, ValidationError),
+
+ (RegexValidator('.*'), '', None),
+ (RegexValidator(re.compile('.*')), '', None),
+ (RegexValidator('.*'), 'xxxxx', None),
+
+ (RegexValidator('x'), 'y', ValidationError),
+ (RegexValidator(re.compile('x')), 'y', ValidationError),
+
)
+
def get_simple_test_func(validator, expected, value, num):
if isinstance(expected, type) and issubclass(expected, Exception):
test_mask = 'test_%s_raises_error_%d'