mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-13 20:08:55 +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()
|
||||
|
||||
@asyncio.coroutine
|
||||
def update_node(self, node, adapter_number, port_number, label=None):
|
||||
for port in self._nodes:
|
||||
if port["node"] == node:
|
||||
if label:
|
||||
port["label"] = label
|
||||
def update_nodes(self, nodes):
|
||||
for node_data in nodes:
|
||||
node = self._project.get_node(node_data["node_id"])
|
||||
for port in self._nodes:
|
||||
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.dump()
|
||||
|
||||
|
@ -90,11 +90,7 @@ class LinkHandler:
|
||||
controller = Controller.instance()
|
||||
project = controller.get_project(request.match_info["project_id"])
|
||||
link = project.get_link(request.match_info["link_id"])
|
||||
for node in 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"))
|
||||
yield from link.update_nodes(request.json["nodes"])
|
||||
response.set_status(201)
|
||||
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__())
|
||||
|
||||
|
||||
def test_update_node(async_run, project, compute):
|
||||
def test_update_nodes(async_run, project, compute):
|
||||
node1 = Node(project, compute, "node1")
|
||||
project._nodes[node1.id] = node1
|
||||
|
||||
link = Link(project)
|
||||
async_run(link.add_node(node1, 0, 4))
|
||||
@ -95,7 +96,7 @@ def test_update_node(async_run, project, compute):
|
||||
}
|
||||
project.dump = AsyncioMagicMock()
|
||||
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 project.dump.called
|
||||
link._project.controller.notification.emit.assert_called_with("link.updated", link.__json__())
|
||||
|
Loading…
Reference in New Issue
Block a user