Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
backbone-message-format
Commits
cbf2982e
Commit
cbf2982e
authored
2 years ago
by
Trishna Saeharaseelan
Browse files
Options
Download
Email Patches
Plain Diff
fix: tests
parent
a6e6290c
2 merge requests
!16
Resolve "Release v0.1"
,
!9
Resolve "Refactor test to not allow schema validation for additional properties & examples"
Pipeline
#108713
passed with stages
in 1 minute and 8 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
265 deletions
+35
-265
examples/autonomy_engine_adapter/planning_configuration.json
examples/autonomy_engine_adapter/planning_configuration.json
+1
-1
examples/autonomy_engine_adapter/platform_status.json
examples/autonomy_engine_adapter/platform_status.json
+0
-2
examples/ecosub_adapter/platform_status.json
examples/ecosub_adapter/platform_status.json
+1
-3
examples/gui_adapter/planning_configuration.json
examples/gui_adapter/planning_configuration.json
+1
-1
formats/platform_status.py
formats/platform_status.py
+1
-0
tests/test_schemas.py
tests/test_schemas.py
+31
-258
No files found.
examples/autonomy_engine_adapter/planning_configuration.json
View file @
cbf2982e
...
...
@@ -9,7 +9,7 @@
"encoded"
:
false
},
"payload"
:{
"message_type"
:
"pla
tform_status
"
,
"message_type"
:
"pla
nning_configuration
"
,
"planning_config_ID"
:
3
,
"exclusion_zones"
:
[
{
...
...
This diff is collapsed.
Click to expand it.
examples/autonomy_engine_adapter/platform_status.json
View file @
cbf2982e
...
...
@@ -15,7 +15,6 @@
"status_source"
:
"onboard_platform"
,
"autonomy_engine_plan_ID"
:
1
,
"battery_remaining_capacity"
:
80.2
,
"active"
:
true
,
"platform_state"
:
"ABORT"
,
"mission_plan_ID"
:
1
,
"mission_track_ID"
:
4
,
...
...
@@ -30,7 +29,6 @@
"usbl_fix_seconds_ago"
:
0
,
"range_to_go"
:
124.3
,
"sensor_config"
:
{
"sensor_ID"
:
22
,
"serial"
:
"sidescan-2x"
,
"sensor_on"
:
true
,
"additional_data"
:
{
...
...
This diff is collapsed.
Click to expand it.
examples/ecosub_adapter/platform_status.json
View file @
cbf2982e
...
...
@@ -15,7 +15,6 @@
"status_source"
:
"onboard_platform"
,
"autonomy_engine_plan_ID"
:
1
,
"battery_remaining_capacity"
:
80.2
,
"active"
:
true
,
"platform_state"
:
"ABORT"
,
"mission_plan_ID"
:
1
,
"mission_track_ID"
:
4
,
...
...
@@ -30,8 +29,7 @@
"usbl_fix_seconds_ago"
:
0
,
"range_to_go"
:
124.3
,
"sensor_config"
:
{
"sensor_ID"
:
22
,
"serial"
:
"sidescan-2x"
,
"sensor_serial"
:
"sidescan-2x"
,
"sensor_on"
:
true
,
"additional_data"
:
{
"whiskers_on"
:
true
...
...
This diff is collapsed.
Click to expand it.
examples/gui_adapter/planning_configuration.json
View file @
cbf2982e
...
...
@@ -9,7 +9,7 @@
"encoded"
:
false
},
"payload"
:{
"message_type"
:
"pla
tform_status
"
,
"message_type"
:
"pla
nning_configuration
"
,
"planning_config_ID"
:
3
,
"exclusion_zones"
:
[
{
...
...
This diff is collapsed.
Click to expand it.
formats/platform_status.py
View file @
cbf2982e
...
...
@@ -18,6 +18,7 @@ sensor_schema = {
"example"
:
True
,
},
"additional_data"
:
{
"type"
:
"object"
,
# TODO: Check 000
"description"
:
"Any addition fields/data to be added here"
,
"example"
:
{
"payload"
:
[
1.2
,
434
]},
},
...
...
This diff is collapsed.
Click to expand it.
tests/test_schemas.py
View file @
cbf2982e
from
openapi_spec_validator
import
openapi_v30_spec_validator
from
openapi_spec_validator.readers
import
read_from_filename
from
openapi_schema_validator
import
validate
from
jsonschema
import
FormatChecker
from
tests.fixtures.schemas
import
(
acknowledgement_schema
,
message_header
,
observation_schema
,
planning_configuration_schema
,
platform_status_schema
,
mission_plan_schema
,
)
from
jsonschema.validators
import
RefResolver
import
unittest
import
json
import
os
from
jsonschema.validators
import
RefResolver
from
openapi_schema_validator
import
validate
# class ValidateResponse:
# def __init__(self, valid, error):
# self.valid = valid
# self.error = error
SCHEMA_DIR
=
"projects/soar/swagger.json"
MOCK_DATA_DIR
=
"examples/"
class
SchemaError
(
Exception
):
"""
Test config specs of swagger.json for projects
"""
def
__init__
(
self
,
exception_type
,
message
):
self
.
type
=
exception_type
self
.
message
=
message
...
...
@@ -42,6 +30,7 @@ class TestSpecs(unittest.TestCase):
schema
,
spec_url
=
read_from_filename
(
"tests/fixtures/swagger.json"
)
self
.
assertIsNone
(
openapi_v30_spec_validator
.
validate
(
schema
))
class
TestAllMessageExamples
(
unittest
.
TestCase
):
def
test_schema_specs
(
self
):
"""
...
...
@@ -51,253 +40,37 @@ class TestAllMessageExamples(unittest.TestCase):
schema
=
json
.
load
(
schema_ref
)
schema_ref
.
close
()
partner_dir_list
=
os
.
listdir
(
MOCK_DATA_DIR
)
for
partner
in
partner_dir_list
:
message_list
=
os
.
listdir
(
os
.
path
.
join
(
MOCK_DATA_DIR
,
partner
))
for
message_type
in
message_list
:
print
(
"Testing message %s by %s now..."
%
(
message_type
,
partner
))
f
=
open
(
os
.
path
.
join
(
MOCK_DATA_DIR
,
partner
,
message_type
))
mock_message
=
json
.
load
(
f
)
ref_resolver
=
RefResolver
.
from_schema
(
schema
)
if
not
partner
.
endswith
(
".py"
):
print
(
"TEST: Partner is %s"
%
partner
.
upper
())
message_list
=
os
.
listdir
(
os
.
path
.
join
(
MOCK_DATA_DIR
,
partner
))
for
message_type
in
message_list
:
if
message_type
.
endswith
(
".json"
):
print
(
"Testing %s now..."
%
message_type
)
f
=
open
(
os
.
path
.
join
(
MOCK_DATA_DIR
,
partner
,
message_type
,
)
)
mock_message
=
json
.
load
(
f
)
ref_resolver
=
RefResolver
.
from_schema
(
schema
)
self
.
assertIsNone
(
validate
(
mock_message
,
schema
[
"components"
][
"schemas"
][
"MESSAGE"
],
resolver
=
ref_resolver
,
)
)
f
.
close
()
print
(
"Done."
)
self
.
assertIsNone
(
validate
(
mock_message
,
schema
[
"components"
][
"schemas"
][
"MESSAGE"
],
resolver
=
ref_resolver
,
)
)
f
.
close
()
schema_ref
.
close
()
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
(),
)
)
f
.
close
()
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
(),
)
)
f
.
close
()
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
(),
)
)
f
.
close
()
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
(),
)
)
f
.
close
()
if
__name__
==
"__main__"
:
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment