Ticket #3250: brian_tests.py

File brian_tests.py, 2.0 KB (added by exogen@…, 18 years ago)

doctests for validators added in #3250

Line 
1__test__ = {'BRIAN_PATCH_TESTS': """
2
3>>> from django.core.validators import *
4>>> v = AllValidators([isLowerCase, isAlphaNumeric, isNotEmpty])
5
6>>> v('abc', '')
7
8>>> v('abC', '')
9Traceback (most recent call last):
10 File "<console>", line 1, in ?
11 File "django/core/validators.py", line 522, in __call__
12ValidationError: ['This field is invalid.']
13
14>>> v('a.c')
15Traceback (most recent call last):
16 File "<console>", line 1, in ?
17TypeError: __call__() takes exactly 3 arguments (2 given)
18
19>>> v('a c', '')
20Traceback (most recent call last):
21 File "<console>", line 1, in ?
22 File "django/core/validators.py", line 522, in __call__
23ValidationError: ['This field is invalid.']
24
25>>> v('', '')
26Traceback (most recent call last):
27 File "<console>", line 1, in ?
28 File "django/core/validators.py", line 522, in __call__
29ValidationError: ['This field is invalid.']
30
31
32>>> v = RequiredIfAllOtherFieldsNotGiven(['email', 'name'])
33
34>>> v('', {'email': '', 'name': ''})
35Traceback (most recent call last):
36 File "<console>", line 1, in ?
37 File "django/core/validators.py", line 499, in __call__
38ValidationError: ['This field must be given if email and name are not given.']
39
40>>> v('22', {'email': '', 'name': ''})
41
42>>> v('22', {'email': 'test@example.com', 'name': ''})
43
44>>> v('', {'email': 'test@example.com', 'name': ''})
45
46
47>>> v = RequiredIfOtherFieldsNotGiven(['email', 'name'])
48
49>>> v('', {'email': 'test@example.com', 'name': 'Brian'})
50
51>>> v('22', {'email': '', 'name': ''})
52
53>>> v('22', {'email': 'test@example.com', 'name': ''})
54
55>>> v('', {'email': '', 'name': ''})
56Traceback (most recent call last):
57 File "<console>", line 1, in ?
58 File "django/core/validators.py", line 522, in __call__
59ValidationError: ['This field must be given if email or name are not given.']
60
61>>> v('', {'email': 'test@example.com', 'name': ''})
62Traceback (most recent call last):
63 File "<console>", line 1, in ?
64 File "django/core/validators.py", line 522, in __call__
65ValidationError: ['This field must be given if email or name are not given.']
66
67"""}
Back to Top