2022-02-07 22:41:13 +00:00
|
|
|
from ansibleplaybookgrapher.graph import (
|
|
|
|
RoleNode,
|
|
|
|
TaskNode,
|
|
|
|
PlayNode,
|
|
|
|
BlockNode,
|
|
|
|
)
|
2021-08-29 16:43:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_links_structure():
|
|
|
|
"""
|
|
|
|
Test links structure of a graph
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
play = PlayNode("composite_node")
|
|
|
|
|
2022-06-17 22:11:16 +00:00
|
|
|
# play -> role -> task 1 and 2
|
2021-08-29 16:43:27 +00:00
|
|
|
role = RoleNode("my_role_1")
|
2022-06-17 22:11:16 +00:00
|
|
|
play.add_node("roles", role)
|
2021-08-29 16:43:27 +00:00
|
|
|
task_1 = TaskNode("task 1")
|
2022-06-17 22:11:16 +00:00
|
|
|
role.add_node("tasks", task_1)
|
2021-08-29 16:43:27 +00:00
|
|
|
task_2 = TaskNode("task 2")
|
2022-06-17 22:11:16 +00:00
|
|
|
role.add_node("tasks", task_2)
|
2021-08-29 16:43:27 +00:00
|
|
|
|
2022-06-17 22:11:16 +00:00
|
|
|
# play -> task 3
|
2021-08-29 16:43:27 +00:00
|
|
|
task_3 = TaskNode("task 3")
|
2022-06-17 22:11:16 +00:00
|
|
|
play.add_node("tasks", task_3)
|
2021-08-29 16:43:27 +00:00
|
|
|
|
|
|
|
all_links = play.links_structure()
|
2022-08-17 20:20:55 +00:00
|
|
|
assert len(all_links) == 2, "The links should contains only 2 elements"
|
2021-08-29 16:43:27 +00:00
|
|
|
|
2022-08-17 20:20:55 +00:00
|
|
|
assert len(all_links[play]) == 2, "The play should be linked to 2 nodes"
|
2022-06-17 22:11:16 +00:00
|
|
|
for e in [role, task_3]:
|
2022-08-17 20:20:55 +00:00
|
|
|
assert e in all_links[play], f"The play should be linked to the task {task_1}"
|
2021-08-29 16:43:27 +00:00
|
|
|
|
2022-08-17 20:20:55 +00:00
|
|
|
assert len(all_links[role]) == 2, "The role should be linked to two nodes"
|
2022-06-17 22:11:16 +00:00
|
|
|
for e in [task_1, task_2]:
|
2022-08-17 20:20:55 +00:00
|
|
|
assert e in all_links[role], f"The role should be linked to the edge {e}"
|
2022-01-06 22:49:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_all_tasks_nodes():
|
|
|
|
"""
|
|
|
|
Test the function get_all_tasks_nodes
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
play = PlayNode("play")
|
|
|
|
|
|
|
|
role_1 = RoleNode("my_role_1")
|
2022-06-17 22:11:16 +00:00
|
|
|
play.add_node("roles", role_1)
|
2022-01-06 22:49:52 +00:00
|
|
|
|
|
|
|
# play -> role 1 -> edge 1 -> task 1
|
|
|
|
task_1 = TaskNode("task 1")
|
2022-06-17 22:11:16 +00:00
|
|
|
role_1.add_node("tasks", task_1)
|
2022-01-06 22:49:52 +00:00
|
|
|
|
|
|
|
# play -> block_1 -> task 2 and task 3
|
|
|
|
block_1 = BlockNode("block 1")
|
|
|
|
task_2 = TaskNode("task 2")
|
|
|
|
task_3 = TaskNode("task 3")
|
|
|
|
block_1.add_node("tasks", task_2)
|
|
|
|
block_1.add_node("tasks", task_3)
|
|
|
|
play.add_node("tasks", block_1)
|
|
|
|
# play -> block_1 -> block_2 -> task 4
|
|
|
|
block_2 = BlockNode("block 2")
|
|
|
|
task_4 = TaskNode("task 4")
|
|
|
|
block_2.add_node("tasks", task_4)
|
|
|
|
block_1.add_node("tasks", block_2)
|
|
|
|
|
2022-06-17 22:11:16 +00:00
|
|
|
all_tasks = play.get_all_tasks()
|
2022-01-06 22:49:52 +00:00
|
|
|
assert len(all_tasks) == 4, "There should be 4 tasks in all"
|
|
|
|
assert [task_1, task_2, task_3, task_4] == all_tasks
|