-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_validatejsonstructure.py
149 lines (140 loc) · 3.99 KB
/
test_validatejsonstructure.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from OSWValidation import json_structure
def test_emptyFeatures_pass():
features = []
invalid_ids = json_structure.validate_json_structure(features)
assert len(invalid_ids) == 0
"""
CROSSINGS
"""
def test_crossing_valid_pass():
features = [{
"type": "Feature",
"properties": {
"highway": "footway",
"footway": "crossing",
"crossing": "marked",
"_u_id": "364328711",
"_v_id": "4561052271"
},
"geometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) == 0
def test_crossing_old_schema_fail():
features = [{
"type": "Feature",
"properties": {
"highway": "footway",
"width": None,
"footway": "crossing",
"crossing": "unmarked",
"length": 2.8
},
"geometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) != 0
def test_crossing_invalid_fail():
features = [{
"type": "Feature",
"properties": {
"highway": "footway",
"width": 10,
"footway": "crossing",
"crossing": "unmarked",
"length": 2.8
},
"gometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) == 1
"""
SIDEWALKS
"""
def test_sidewalk_valid_pass():
features = [{
"type": "Feature",
"properties": {
"highway": "footway",
"footway": "sidewalk",
"_u_id": "364328711",
"_v_id": "4561052271"
},
"geometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) == 0
def test_sidewalk_missing_vid_uid_fail():
features = [{
"type": "Feature",
"properties": {
"highway": "footway",
"footway": "sidewalk",
},
"geometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) != 0
def test_sidewalk_wrong_type_vid_uid_fail():
features = [{
"type": "Feature",
"properties": {
"_v_id": 364328711,
"_u_id": 4561052271,
"highway": "footway",
"footway": "sidewalk",
},
"geometry": {
"type": "LineString",
"coordinates": [
[ -71.6266856, -33.0416369 ],
[ -71.6266685, -33.0416575 ]
]
}
}]
geojson = generate_geojson_from_features(features)
invalid_ids = json_structure.validate_json_structure(geojson)
assert len(invalid_ids) != 0
"""
Helper functions:
"""
def generate_geojson_from_features(features):
return {
"type": "FeatureCollection",
"features": features
}