mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Item => Shape
This commit is contained in:
12 files changed
+125
-125
No files matched your search
@@ -213,30 +213,30 @@ def test_deleteLink(async_run, project, controller):
|
||||
assert len(project._links) == 0
|
||||
|
||||
|
||||
def test_addItem(async_run, project, controller):
|
||||
def test_addShape(async_run, project, controller):
|
||||
controller.notification.emit = MagicMock()
|
||||
|
||||
item = async_run(project.add_item(None, svg="<svg></svg>"))
|
||||
assert len(project._items) == 1
|
||||
controller.notification.emit.assert_any_call("item.created", item.__json__())
|
||||
shape = async_run(project.add_shape(None, svg="<svg></svg>"))
|
||||
assert len(project._shapes) == 1
|
||||
controller.notification.emit.assert_any_call("shape.created", shape.__json__())
|
||||
|
||||
|
||||
def test_getItem(async_run, project):
|
||||
item = async_run(project.add_item(None))
|
||||
assert project.get_item(item.id) == item
|
||||
def test_getShape(async_run, project):
|
||||
shape = async_run(project.add_shape(None))
|
||||
assert project.get_shape(shape.id) == shape
|
||||
|
||||
with pytest.raises(aiohttp.web_exceptions.HTTPNotFound):
|
||||
project.get_item("test")
|
||||
project.get_shape("test")
|
||||
|
||||
|
||||
def test_deleteItem(async_run, project, controller):
|
||||
assert len(project._items) == 0
|
||||
item = async_run(project.add_item())
|
||||
assert len(project._items) == 1
|
||||
def test_deleteShape(async_run, project, controller):
|
||||
assert len(project._shapes) == 0
|
||||
shape = async_run(project.add_shape())
|
||||
assert len(project._shapes) == 1
|
||||
controller._notification = MagicMock()
|
||||
async_run(project.delete_item(item.id))
|
||||
controller.notification.emit.assert_any_call("item.deleted", item.__json__())
|
||||
assert len(project._items) == 0
|
||||
async_run(project.delete_shape(shape.id))
|
||||
controller.notification.emit.assert_any_call("shape.deleted", shape.__json__())
|
||||
assert len(project._shapes) == 0
|
||||
|
||||
|
||||
def test_delete(async_run, project, controller):
|
||||
|
||||
@@ -22,7 +22,7 @@ import uuid
|
||||
from tests.utils import AsyncioMagicMock
|
||||
|
||||
|
||||
from gns3server.controller.item import Item
|
||||
from gns3server.controller.shape import Shape
|
||||
from gns3server.controller.project import Project
|
||||
|
||||
|
||||
@@ -32,43 +32,43 @@ def project(controller, async_run):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def item(project):
|
||||
return Item(project, None, svg="<svg></svg>")
|
||||
def shape(project):
|
||||
return Shape(project, None, svg="<svg></svg>")
|
||||
|
||||
|
||||
def test_init_without_uuid(project):
|
||||
item = Item(project, None, svg="<svg></svg>")
|
||||
assert item.id is not None
|
||||
shape = Shape(project, None, svg="<svg></svg>")
|
||||
assert shape.id is not None
|
||||
|
||||
|
||||
def test_init_with_uuid(project):
|
||||
id = str(uuid.uuid4())
|
||||
item = Item(project, id, svg="<svg></svg>")
|
||||
assert item.id == id
|
||||
shape = Shape(project, id, svg="<svg></svg>")
|
||||
assert shape.id == id
|
||||
|
||||
|
||||
def test_json(project):
|
||||
i = Item(project, None, svg="<svg></svg>")
|
||||
i = Shape(project, None, svg="<svg></svg>")
|
||||
assert i.__json__() == {
|
||||
"item_id": i.id,
|
||||
"shape_id": i.id,
|
||||
"project_id": project.id,
|
||||
"x": i.x,
|
||||
"y": i.y,
|
||||
"z": i.z
|
||||
}
|
||||
assert i.__json__(topology_dump=True) == {
|
||||
"item_id": i.id,
|
||||
"shape_id": i.id,
|
||||
"x": i.x,
|
||||
"y": i.y,
|
||||
"z": i.z
|
||||
}
|
||||
|
||||
|
||||
def test_update(item, project, async_run, controller):
|
||||
def test_update(shape, project, async_run, controller):
|
||||
controller._notification = AsyncioMagicMock()
|
||||
project.dump = MagicMock()
|
||||
|
||||
async_run(item.update(x=42))
|
||||
assert item.x == 42
|
||||
controller._notification.emit.assert_called_with("item.updated", item.__json__())
|
||||
async_run(shape.update(x=42))
|
||||
assert shape.x == 42
|
||||
controller._notification.emit.assert_called_with("shape.updated", shape.__json__())
|
||||
assert project.dump.called
|
||||
@@ -38,7 +38,7 @@ def test_project_to_topology_empty(tmpdir):
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"items": []
|
||||
"shapes": []
|
||||
},
|
||||
"type": "topology",
|
||||
"version": __version__
|
||||
@@ -58,14 +58,14 @@ def test_basic_topology(tmpdir, async_run, controller):
|
||||
async_run(link.add_node(node1, 0, 0))
|
||||
async_run(link.add_node(node2, 0, 0))
|
||||
|
||||
item = async_run(project.add_item(svg="<svg></svg>"))
|
||||
shape = async_run(project.add_shape(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"]["items"][0] == item.__json__(topology_dump=True)
|
||||
assert topo["topology"]["shapes"][0] == shape.__json__(topology_dump=True)
|
||||
|
||||
|
||||
def test_load_topology(tmpdir):
|
||||
@@ -77,7 +77,7 @@ def test_load_topology(tmpdir):
|
||||
"nodes": [],
|
||||
"links": [],
|
||||
"computes": [],
|
||||
"items": []
|
||||
"shapes": []
|
||||
},
|
||||
"type": "topology",
|
||||
"version": __version__}
|
||||
|
||||
Reference in new issue
Block a user