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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
from openapi_spec_validator import openapi_v30_spec_validator, openapi_v3_spec_validator
from openapi_spec_validator.readers import read_from_filename
from openapi_schema_validator import validate
from jsonschema import FormatChecker
from jsonschema import validate
import unittest
from tests.fixtures.schemas import (
acknowledgement_schema,
message_header,
observation_schema,
planning_configuration_schema,
platform_status_schema,
mission_plan_schema,
)
import json
class TestSpecs(unittest.TestCase):
def test_swagger_specs(self):
"""
Test specs (swagger.json generated from generate_schema_config.py)
"""
schema, spec_url = read_from_filename("tests/fixtures/swagger.json")
self.assertIsNone(openapi_v30_spec_validator.validate(schema))
class TestSchema(unittest.TestCase):
def test_sample_hydrosurv_messages(self):
"""
Test schema - Hydrosurv Messages
"""
message_types = ["acknowledgement", "mission_plan", "platform_status"]
for item in message_types:
f = open("examples/hydrosurv_adapter/%s.json" % item)
mock_data = json.load(f)
header_data = mock_data["header"]
payload_data = mock_data["payload"]
self.assertIsNone(validate(header_data, message_header, format_checker=FormatChecker()))
if item == "acknowledgement":
self.assertIsNone(
validate(
payload_data, acknowledgement_schema, format_checker=FormatChecker()
)
)
elif item == "mission_plan":
self.assertIsNone(
validate(payload_data, mission_plan_schema, format_checker=FormatChecker())
)
elif item == "platform_status":
self.assertIsNone(
validate(
payload_data, platform_status_schema, format_checker=FormatChecker()
)
)
def test_sample_gui_messages(self):
"""
Test schema - GUI Messages
"""
message_types = ["planning_configuration"]
for item in message_types:
f = open("examples/gui_adapter/%s.json" % item)
mock_data = json.load(f)
header_data = mock_data["header"]
payload_data = mock_data["payload"]
self.assertIsNone(validate(header_data, message_header, format_checker=FormatChecker()))
if item == "planning_configuration":
self.assertIsNone(
validate(
payload_data,
planning_configuration_schema,
format_checker=FormatChecker(),
)
)
def test_sample_ecosub_messages(self):
"""
Test schema - Ecosub Messages
"""
message_types = [
"observation",
"mission_plan",
"platform_status",
"platform_status-from_usbl_example",
]
for item in message_types:
f = open("examples/ecosub_adapter/%s.json" % item)
mock_data = json.load(f)
header_data = mock_data["header"]
payload_data = mock_data["payload"]
self.assertIsNone(validate(header_data, message_header, format_checker=FormatChecker()))
if item == "platform_status-from_usbl_example.json":
self.assertIsNone(
validate(
payload_data, platform_status_schema, format_checker=FormatChecker()
)
)
elif item == "mission_plan":
self.assertIsNone(
validate(payload_data, mission_plan_schema, format_checker=FormatChecker())
)
elif item == "platform_status":
self.assertIsNone(
validate(
payload_data, platform_status_schema, format_checker=FormatChecker()
)
)
elif item == "observation":
self.assertIsNone(
validate(payload_data, observation_schema, format_checker=FormatChecker())
)
def test_sample_autonomy_engine_messages(self):
"""
Test schema - Autonomy Engine Messages
"""
message_types = [
"planning_configuration",
"mission_plan_AH1",
"mission_plan_ECOSUB",
"mission_plan_HYDROSURV",
"platform_status",
"platform_status-from_usbl_example",
"acknowledgement",
]
for item in message_types:
f = open("examples/autonomy_engine_adapter/%s.json" % item)
mock_data = json.load(f)
header_data = mock_data["header"]
payload_data = mock_data["payload"]
self.assertIsNone(validate(header_data, message_header, format_checker=FormatChecker()))
if item == "platform_status-from_usbl_example.json":
self.assertIsNone(
validate(
payload_data, platform_status_schema, format_checker=FormatChecker()
)
)
elif item == "mission_plan_AH1":
self.assertIsNone(
validate(payload_data, mission_plan_schema, format_checker=FormatChecker())
)
elif item == "mission_plan_ECOSUB":
self.assertIsNone(
validate(payload_data, mission_plan_schema, format_checker=FormatChecker())
)
elif item == "mission_plan_HYDROSURV":
self.assertIsNone(
validate(payload_data, mission_plan_schema, format_checker=FormatChecker())
)
elif item == "platform_status":
self.assertIsNone(
validate(
payload_data, platform_status_schema, format_checker=FormatChecker()
)
)
elif item == "observation":
self.assertIsNone(
validate(payload_data, observation_schema, format_checker=FormatChecker())
)
elif item == "planning_configuration":
self.assertIsNone(
validate(
payload_data,
planning_configuration_schema,
format_checker=FormatChecker(),
)
)
elif item == "acknowledgement":
self.assertIsNone(
validate(
payload_data, acknowledgement_schema, format_checker=FormatChecker()
)
)
if __name__ == '__main__':
unittest.main()