def test_basic_topology(tmpdir, async_run, controller): project = Project(name="Test", controller=controller) compute = Compute("my_compute", controller) compute.http_query = MagicMock() with asyncio_patch("gns3server.controller.node.Node.create"): node1 = async_run( project.add_node(compute, "Node 1", str(uuid.uuid4()), node_type="qemu")) node2 = async_run( project.add_node(compute, "Node 2", str(uuid.uuid4()), node_type="qemu")) link = async_run(project.add_link()) async_run(link.add_node(node1, 0, 0)) with asyncio_patch("gns3server.controller.udp_link.UDPLink.create" ) as mock_udp_create: async_run(link.add_node(node2, 0, 0)) drawing = async_run(project.add_drawing(svg="<svg></svg>")) topo = project_to_topology(project) assert len(topo["topology"]["nodes"]) == 2 assert node1.__json__(topology_dump=True) in topo["topology"]["nodes"] assert topo["topology"]["links"][0] == link.__json__(topology_dump=True) assert topo["topology"]["computes"][0] == compute.__json__( topology_dump=True) assert topo["topology"]["drawings"][0] == drawing.__json__( topology_dump=True)
def test_project_to_topology(tmpdir, controller): variables = [{"name": "TEST1"}, {"name": "TEST2", "value": "value1"}] supplier = {'logo': 'logo.png', 'url': 'http://example.com'} project = Project(name="Test", controller=controller) compute = Compute("my_compute", controller) compute.http_query = MagicMock() project.variables = variables project.supplier = supplier topo = project_to_topology(project) assert topo["variables"] == variables assert topo["supplier"] == supplier
def test_project_to_topology(tmpdir, controller): variables = [ {"name": "TEST1"}, {"name": "TEST2", "value": "value1"} ] supplier = { 'logo': 'logo.png', 'url': 'http://example.com' } project = Project(name="Test", controller=controller) compute = Compute("my_compute", controller) compute.http_query = MagicMock() project.variables = variables project.supplier = supplier topo = project_to_topology(project) assert topo["variables"] == variables assert topo["supplier"] == supplier
def test_basic_topology(tmpdir, async_run, controller): project = Project(name="Test", controller=controller) compute = Compute("my_compute", controller) compute.http_query = MagicMock() with asyncio_patch("gns3server.controller.node.Node.create"): node1 = async_run(project.add_node(compute, "Node 1", str(uuid.uuid4()), node_type="qemu")) node2 = async_run(project.add_node(compute, "Node 2", str(uuid.uuid4()), node_type="qemu")) link = async_run(project.add_link()) async_run(link.add_node(node1, 0, 0)) with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock_udp_create: async_run(link.add_node(node2, 0, 0)) drawing = async_run(project.add_drawing(svg="<svg></svg>")) topo = project_to_topology(project) assert len(topo["topology"]["nodes"]) == 2 assert node1.__json__(topology_dump=True) in topo["topology"]["nodes"] assert topo["topology"]["links"][0] == link.__json__(topology_dump=True) assert topo["topology"]["computes"][0] == compute.__json__(topology_dump=True) assert topo["topology"]["drawings"][0] == drawing.__json__(topology_dump=True)