forked from core-api/python-coreschema
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_string.py
More file actions
47 lines (33 loc) · 1.41 KB
/
test_string.py
File metadata and controls
47 lines (33 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from coreschema import String
def test_string_type():
schema = String()
assert schema.validate('') == []
assert schema.validate('abc') == []
assert schema.validate(123) == [('Must be a string.', [])]
def test_max_length():
schema = String(max_length=3)
assert schema.validate('abc') == []
assert schema.validate('abcd') == [('Must have no more than 3 characters.', [])]
def test_min_length():
schema = String(min_length=3)
assert schema.validate('abc') == []
assert schema.validate('ab') == [('Must have at least 3 characters.', [])]
def test_blank():
schema = String(min_length=1)
assert schema.validate('abc') == []
assert schema.validate('') == [('Must not be blank.', [])]
def test_pattern():
schema = String(pattern='^a[0-9]$')
assert schema.validate('a3') == []
assert schema.validate('ab') == [('Must match the pattern /^a[0-9]$/.', [])]
schema = String(pattern='a[0-9]')
assert schema.validate('z a3 z') == []
assert schema.validate('z ab z ') == [('Must match the pattern /a[0-9]/.', [])]
def test_format_email():
schema = String(format='email')
assert schema.validate('a@b') == []
assert schema.validate('ab@') == [('Must be a valid email.', [])]
def test_format_uri():
schema = String(format='uri')
assert schema.validate('http://example.com') == []
assert schema.validate('example.com') == [('Must be a valid uri.', [])]