-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_doolally.py
91 lines (78 loc) · 1.82 KB
/
test_doolally.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import pytest
from doolally import (
validate,
jsonschema,
ValidationValueError,
ValidationTypeError,
)
from testexamples import *
def test_animals():
p1 = {
"pet": {
"name": "Dave",
"age": 5,
"breed": "German Shepherd",
},
}
validate(p1, AnimalPerson)
p2 = {
"pet": {
"name": "Mr. Tiddles",
"age": 11,
"breed": "Burmese",
},
}
validate(p2, AnimalPerson)
# Missing pet key
p3 = {
"boo": {},
}
with pytest.raises(ValidationValueError):
validate(p3, AnimalPerson)
# Pet has wrong JSON type
p4 = {
"pet": ["Mr. Tiddles", "Clyde"],
}
with pytest.raises(ValidationValueError):
validate(p4, AnimalPerson)
# Non Integer age
p5 = {
"pet": {
"name": "Dave",
"age": 15.4,
"breed": "German Shepherd",
},
}
with pytest.raises(ValidationValueError):
validate(p5, AnimalPerson)
def test_email():
e1 = {
"provider": None,
}
validate(e1, EmailAddr)
e2 = {
"provider": "gmail",
}
validate(e2, EmailAddr)
def test_numbers():
n1 = {
"numbers": [
"one",
1,
"4",
"ten",
7,
],
}
validate(n1, Numbers)
valid_latitudes = 34.5, 0, 90, 12
for v in valid_latitudes:
validate({"latitude": v}, Numbers)
invalid_latitudes = -0.01, 90.01, 100
for v in invalid_latitudes:
with pytest.raises(ValidationValueError):
validate({"latitude": v}, Numbers)
wrong_type_latitudes = "56.4", {"value": 15}
for v in wrong_type_latitudes:
with pytest.raises(ValidationTypeError):
validate({"latitude": v}, Numbers)