1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-29 02:08:10 +00:00

Send node.updated notif only if object changed

This commit is contained in:
Julien Duponchelle 2016-06-30 18:29:17 +02:00
parent 758a427a76
commit fe7bcae6a1
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
3 changed files with 24 additions and 11 deletions

View File

@ -214,6 +214,8 @@ class Node:
# When updating properties used only on controller we don't need to call the compute
update_compute = False
old_json = self.__json__()
compute_properties = None
# Update node properties with additional elements
for prop in kwargs:
@ -227,7 +229,9 @@ class Node:
else:
setattr(self, prop, kwargs[prop])
self.project.controller.notification.emit("node.updated", self.__json__())
# We send notif only if object has changed
if old_json != self.__json__():
self.project.controller.notification.emit("node.updated", self.__json__())
if update_compute:
data = self._node_data(properties=compute_properties)
response = yield from self.put(None, data=data)
@ -392,9 +396,9 @@ class Node:
"console_type": self._console_type,
"properties": self._properties,
"label": self._label,
"x": self._x,
"y": self._y,
"z": self._z,
"x": int(self._x),
"y": int(self._y),
"z": int(self._z),
"symbol": self._symbol
}
return {
@ -411,8 +415,8 @@ class Node:
"properties": self._properties,
"status": self._status,
"label": self._label,
"x": self._x,
"y": self._y,
"z": self._z,
"x": int(self._x),
"y": int(self._y),
"z": int(self._z),
"symbol": self._symbol
}

View File

@ -146,15 +146,15 @@ NODE_OBJECT_SCHEMA = {
},
"x": {
"description": "X position of the node",
"type": "number"
"type": "integer"
},
"y": {
"description": "Y position of the node",
"type": "number"
"type": "integer"
},
"z": {
"description": "Z position of the node",
"type": "number"
"type": "integer"
}
},
"additionalProperties": False,

View File

@ -186,16 +186,25 @@ def test_update_properties(node, compute, project, async_run, controller):
controller._notification.emit.assert_called_with("node.updated", node_notif)
def test_update_only_controller(node, compute, project, async_run):
def test_update_only_controller(node, controller, compute, project, async_run):
"""
When updating property used only on controller we don't need to
call the compute
"""
compute.put = AsyncioMagicMock()
controller._notification = AsyncioMagicMock()
async_run(node.update(x=42))
assert not compute.put.called
assert node.x == 42
controller._notification.emit.assert_called_with("node.updated", node.__json__())
# If nothing change a second notif should not be send
controller._notification = AsyncioMagicMock()
async_run(node.update(x=42))
assert not controller._notification.emit.called
def test_update_no_changes(node, compute, project, async_run):