diff --git a/tests/isar/models/example_mission_definition.json b/tests/isar/models/example_mission_definition.json new file mode 100644 index 00000000..fbe1bccd --- /dev/null +++ b/tests/isar/models/example_mission_definition.json @@ -0,0 +1,40 @@ +{ + "tasks": [ + { + "pose": { + "position": { + "x": 0, + "y": 0, + "z": 0, + "frame_name": "robot" + }, + "orientation": { + "x": 0, + "y": 0, + "z": 0, + "w": 0, + "frame_name": "robot" + }, + "frame_name": "robot" + }, + "inspections": [ + { + "type": "Image", + "inspection_target": { + "x": 0, + "y": 0, + "z": 0, + "frame_name": "robot" + }, + "duration": 0, + "metadata": {}, + "id": "generated_inspection_id" + } + ], + "tag": "MY-TAG-123", + "id": "generated_task_id" + } + ], + "id": "generated_mission_id", + "name": "my-mission" +} diff --git a/tests/isar/models/test_start_mission_definition.py b/tests/isar/models/test_start_mission_definition.py index 36136c00..c5a4b3a0 100644 --- a/tests/isar/models/test_start_mission_definition.py +++ b/tests/isar/models/test_start_mission_definition.py @@ -1,8 +1,16 @@ +import json +import os from typing import List, Union import pytest +from alitra import Frame, Orientation, Pose, Position -from isar.apis.models.start_mission_definition import get_duplicate_ids +from isar.apis.models.start_mission_definition import ( + StartMissionDefinition, + get_duplicate_ids, + to_isar_mission, +) +from robot_interface.models.mission.mission import Mission from robot_interface.models.mission.step import STEPS, Step from robot_interface.models.mission.task import Task @@ -51,3 +59,36 @@ def test_duplicate_id_check( duplicates: List[str] = get_duplicate_ids(item_list) has_duplicates: bool = len(duplicates) > 0 assert has_duplicates == expected_boolean + + +def test_mission_definition_to_isar_mission(): + dirname = os.path.dirname(__file__) + filepath = os.path.join(dirname, "example_mission_definition.json") + + with open(filepath) as f: + datax = json.load(f) + mission_definition = StartMissionDefinition(**datax) + + generated_mission: Mission = to_isar_mission(mission_definition) + assert generated_mission.id == "generated_mission_id" + assert generated_mission.name == "my-mission" + assert len(generated_mission.tasks) == 1 + + task = generated_mission.tasks[0] + assert task.id == "generated_task_id" + assert task.tag_id == "MY-TAG-123" + + first_step = task.steps[0] + # assert first_step.id == "generated_inspection_id" + assert first_step.type == "drive_to_pose" + assert first_step.pose == Pose( + position=Position(0.0, 0.0, 0.0, frame=Frame("robot")), + orientation=Orientation(0.0, 0.0, 0.0, 0.0, frame=Frame("robot")), + frame=Frame("robot"), + ) + + second_step = task.steps[1] + # assert second_step.id == "generated_inspection_id" + assert second_step.type == "take_image" + assert second_step.tag_id == "MY-TAG-123" + assert second_step.target == Position(0.0, 0.0, 0.0, frame=Frame("robot"))