def test_add_node(async_run, project, compute): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] link = Link(project) link.create = AsyncioMagicMock() link._project.emit_notification = MagicMock() project.dump = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) assert link._nodes == [ { "node": node1, "port": node1._ports[0], "adapter_number": 0, "port_number": 4, 'label': { 'text': '0/4', 'style': 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;' } } ] assert project.dump.called assert not link._project.emit_notification.called assert not link.create.called # We call link.created only when both side are created node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 0, 4)] async_run(link.add_node(node2, 0, 4)) assert link.create.called link._project.emit_notification.assert_called_with("link.created", link.__json__()) assert link in node2.links
def test_json_serial_link(async_run, project, compute, link): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [SerialPort("S0", 0, 0, 4)] node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [SerialPort("S0", 0, 1, 3)] link = Link(project) link.create = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) async_run(link.add_node(node2, 1, 3)) assert link.__json__()["link_type"] == "serial"
def test_add_node(async_run, project, compute): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] link = Link(project) link.create = AsyncioMagicMock() link._project.controller.notification.emit = MagicMock() project.dump = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) assert link._nodes == [ { "node": node1, "port": node1._ports[0], "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } } ] assert project.dump.called assert not link._project.controller.notification.emit.called assert not link.create.called # We call link.created only when both side are created node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 0, 4)] async_run(link.add_node(node2, 0, 4)) assert link.create.called link._project.controller.notification.emit.assert_called_with("link.created", link.__json__()) assert link in node2.link
def test_add_node(async_run, project, compute): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] link = Link(project) link.create = AsyncioMagicMock() link._project.controller.notification.emit = MagicMock() project.dump = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) assert link._nodes == [{ "node": node1, "port": node1._ports[0], "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }] assert project.dump.called assert not link._project.controller.notification.emit.called assert not link.create.called # We call link.created only when both side are created node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 0, 4)] async_run(link.add_node(node2, 0, 4)) assert link.create.called link._project.controller.notification.emit.assert_called_with( "link.created", link.__json__()) assert link in node2.link
def test_json(async_run, project, compute, link): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 1, 3)] link = Link(project) link.create = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) async_run(link.add_node(node2, 1, 3)) assert link.__json__() == { "link_id": link.id, "project_id": project.id, "nodes": [{ "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'y': -10, 'text': '1/3', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }], "link_type": "ethernet", "capturing": False, "capture_file_name": None, "capture_file_path": None } assert link.__json__(topology_dump=True) == { "link_id": link.id, "nodes": [{ "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'y': -10, 'text': '1/3', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }] }
def test_json(async_run, project, compute, link): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 1, 3)] link = Link(project) link.create = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) async_run(link.add_node(node2, 1, 3)) assert link.__json__() == { "link_id": link.id, "project_id": project.id, "nodes": [ { "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'y': -10, 'text': '1/3', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } } ], "link_type": "ethernet", "capturing": False, "capture_file_name": None, "capture_file_path": None } assert link.__json__(topology_dump=True) == { "link_id": link.id, "nodes": [ { "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'y': -10, 'text': '0/4', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'y': -10, 'text': '1/3', 'x': -10, 'rotation': 0, 'style': 'font-size: 10; font-style: Verdana' } } ] }
def test_json(async_run, project, compute, link): node1 = Node(project, compute, "node1", node_type="qemu") node1._ports = [EthernetPort("E0", 0, 0, 4)] node2 = Node(project, compute, "node2", node_type="qemu") node2._ports = [EthernetPort("E0", 0, 1, 3)] link = Link(project) link.create = AsyncioMagicMock() async_run(link.add_node(node1, 0, 4)) async_run(link.add_node(node2, 1, 3)) assert link.__json__() == { "link_id": link.id, "project_id": project.id, "nodes": [ { "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'text': '0/4', 'style': 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'text': '1/3', 'style': 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;' } } ], "filters": {}, "suspend": False, "link_type": "ethernet", "capturing": False, "capture_file_name": None, "capture_file_path": None, "capture_compute_id": None } assert link.__json__(topology_dump=True) == { "link_id": link.id, "nodes": [ { "node_id": node1.id, "adapter_number": 0, "port_number": 4, 'label': { 'text': '0/4', 'style': 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;' } }, { "node_id": node2.id, "adapter_number": 1, "port_number": 3, 'label': { 'text': '1/3', 'style': 'font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;' } } ], "filters": {}, "suspend": False }