mirror of
https://github.com/GNS3/gns3-server
synced 2025-02-26 07:02:12 +00:00
Ensure we update all the label of a link with only one update notif
This commit is contained in:
parent
9d2f4168ff
commit
7fee90805b
@ -70,11 +70,14 @@ class Link:
|
|||||||
self._project.dump()
|
self._project.dump()
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def update_node(self, node, adapter_number, port_number, label=None):
|
def update_nodes(self, nodes):
|
||||||
for port in self._nodes:
|
for node_data in nodes:
|
||||||
if port["node"] == node:
|
node = self._project.get_node(node_data["node_id"])
|
||||||
if label:
|
for port in self._nodes:
|
||||||
port["label"] = label
|
if port["node"] == node:
|
||||||
|
label = node_data.get("label")
|
||||||
|
if label:
|
||||||
|
port["label"] = label
|
||||||
self._project.controller.notification.emit("link.updated", self.__json__())
|
self._project.controller.notification.emit("link.updated", self.__json__())
|
||||||
self._project.dump()
|
self._project.dump()
|
||||||
|
|
||||||
|
@ -90,11 +90,7 @@ class LinkHandler:
|
|||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
project = controller.get_project(request.match_info["project_id"])
|
project = controller.get_project(request.match_info["project_id"])
|
||||||
link = project.get_link(request.match_info["link_id"])
|
link = project.get_link(request.match_info["link_id"])
|
||||||
for node in request.json["nodes"]:
|
yield from link.update_nodes(request.json["nodes"])
|
||||||
yield from link.update_node(project.get_node(node["node_id"]),
|
|
||||||
node.get("adapter_number", 0),
|
|
||||||
node.get("port_number", 0),
|
|
||||||
label=node.get("label"))
|
|
||||||
response.set_status(201)
|
response.set_status(201)
|
||||||
response.json(link)
|
response.json(link)
|
||||||
|
|
||||||
|
@ -81,8 +81,9 @@ def test_add_node(async_run, project, compute):
|
|||||||
link._project.controller.notification.emit.assert_called_with("link.created", link.__json__())
|
link._project.controller.notification.emit.assert_called_with("link.created", link.__json__())
|
||||||
|
|
||||||
|
|
||||||
def test_update_node(async_run, project, compute):
|
def test_update_nodes(async_run, project, compute):
|
||||||
node1 = Node(project, compute, "node1")
|
node1 = Node(project, compute, "node1")
|
||||||
|
project._nodes[node1.id] = node1
|
||||||
|
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
async_run(link.add_node(node1, 0, 4))
|
async_run(link.add_node(node1, 0, 4))
|
||||||
@ -95,7 +96,7 @@ def test_update_node(async_run, project, compute):
|
|||||||
}
|
}
|
||||||
project.dump = AsyncioMagicMock()
|
project.dump = AsyncioMagicMock()
|
||||||
link._project.controller.notification.emit = MagicMock()
|
link._project.controller.notification.emit = MagicMock()
|
||||||
async_run(link.update_node(node1, 0, 4, label=label))
|
async_run(link.update_nodes([{"node_id": node1.id, "label": label}]))
|
||||||
assert link._nodes[0]["label"]["y"] == -42
|
assert link._nodes[0]["label"]["y"] == -42
|
||||||
assert project.dump.called
|
assert project.dump.called
|
||||||
link._project.controller.notification.emit.assert_called_with("link.updated", link.__json__())
|
link._project.controller.notification.emit.assert_called_with("link.updated", link.__json__())
|
||||||
|
Loading…
Reference in New Issue
Block a user