Shape => Drawing

This commit is contained in:
Julien Duponchelle committed 2016-06-23 11:17:23 +02:00
1 parent c847755f1b
commit 852d8e411e
21 files changed
+181 -181

No files matched your search

+15 -15
View File
@@ -213,30 +213,30 @@ def test_deleteLink(async_run, project, controller):
assert len(project._links) == 0
def test_addShape(async_run, project, controller):
def test_addDrawing(async_run, project, controller):
controller.notification.emit = MagicMock()
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__())
drawing = async_run(project.add_drawing(None, svg="<svg></svg>"))
assert len(project._drawings) == 1
controller.notification.emit.assert_any_call("drawing.created", drawing.__json__())
def test_getShape(async_run, project):
shape = async_run(project.add_shape(None))
assert project.get_shape(shape.id) == shape
def test_getDrawing(async_run, project):
drawing = async_run(project.add_drawing(None))
assert project.get_drawing(drawing.id) == drawing
with pytest.raises(aiohttp.web_exceptions.HTTPNotFound):
project.get_shape("test")
project.get_drawing("test")
def test_deleteShape(async_run, project, controller):
assert len(project._shapes) == 0
shape = async_run(project.add_shape())
assert len(project._shapes) == 1
def test_deleteDrawing(async_run, project, controller):
assert len(project._drawings) == 0
drawing = async_run(project.add_drawing())
assert len(project._drawings) == 1
controller._notification = MagicMock()
async_run(project.delete_shape(shape.id))
controller.notification.emit.assert_any_call("shape.deleted", shape.__json__())
assert len(project._shapes) == 0
async_run(project.delete_drawing(drawing.id))
controller.notification.emit.assert_any_call("drawing.deleted", drawing.__json__())
assert len(project._drawings) == 0
def test_delete(async_run, project, controller):
+17 -17
View File
@@ -22,7 +22,7 @@ import uuid
from tests.utils import AsyncioMagicMock
from gns3server.controller.shape import Shape
from gns3server.controller.drawing import Drawing
from gns3server.controller.project import Project
@@ -32,25 +32,25 @@ def project(controller, async_run):
@pytest.fixture
def shape(project):
return Shape(project, None, svg="<svg></svg>")
def drawing(project):
return Drawing(project, None, svg="<svg></svg>")
def test_init_without_uuid(project):
shape = Shape(project, None, svg="<svg></svg>")
assert shape.id is not None
drawing = Drawing(project, None, svg="<svg></svg>")
assert drawing.id is not None
def test_init_with_uuid(project):
id = str(uuid.uuid4())
shape = Shape(project, id, svg="<svg></svg>")
assert shape.id == id
drawing = Drawing(project, id, svg="<svg></svg>")
assert drawing.id == id
def test_json(project):
i = Shape(project, None, svg="<svg></svg>")
i = Drawing(project, None, svg="<svg></svg>")
assert i.__json__() == {
"shape_id": i.id,
"drawing_id": i.id,
"project_id": project.id,
"x": i.x,
"y": i.y,
@@ -59,7 +59,7 @@ def test_json(project):
"rotation": i.rotation
}
assert i.__json__(topology_dump=True) == {
"shape_id": i.id,
"drawing_id": i.id,
"x": i.x,
"y": i.y,
"z": i.z,
@@ -68,22 +68,22 @@ def test_json(project):
}
def test_update(shape, project, async_run, controller):
def test_update(drawing, project, async_run, controller):
controller._notification = AsyncioMagicMock()
project.dump = MagicMock()
async_run(shape.update(x=42, svg="<svg><rect></rect></svg>"))
assert shape.x == 42
async_run(drawing.update(x=42, svg="<svg><rect></rect></svg>"))
assert drawing.x == 42
args, kwargs = controller._notification.emit.call_args
assert args[0] == "shape.updated"
assert args[0] == "drawing.updated"
# JSON
assert args[1]["x"] == 42
assert args[1]["svg"] == "<svg><rect></rect></svg>"
async_run(shape.update(x=12, svg="<svg><rect></rect></svg>"))
assert shape.x == 12
async_run(drawing.update(x=12, svg="<svg><rect></rect></svg>"))
assert drawing.x == 12
args, kwargs = controller._notification.emit.call_args
assert args[0] == "shape.updated"
assert args[0] == "drawing.updated"
# JSON
assert args[1]["x"] == 12
# To avoid spamming client with large data we don't send the svg if the SVG didn't change
+4 -4
View File
@@ -38,7 +38,7 @@ def test_project_to_topology_empty(tmpdir):
"nodes": [],
"links": [],
"computes": [],
"shapes": []
"drawings": []
},
"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))
shape = async_run(project.add_shape(svg="<svg></svg>"))
drawing = async_run(project.add_drawing(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"]["shapes"][0] == shape.__json__(topology_dump=True)
assert topo["topology"]["drawings"][0] == drawing.__json__(topology_dump=True)
def test_load_topology(tmpdir):
@@ -77,7 +77,7 @@ def test_load_topology(tmpdir):
"nodes": [],
"links": [],
"computes": [],
"shapes": []
"drawings": []
},
"type": "topology",
"version": __version__}
+15 -15
View File
@@ -30,7 +30,7 @@ from tests.utils import asyncio_patch
from gns3server.handlers.api.controller.project_handler import ProjectHandler
from gns3server.controller import Controller
from gns3server.controller.shape import Shape
from gns3server.controller.drawing import Drawing
@@ -39,49 +39,49 @@ def project(http_controller, async_run):
return async_run(Controller.instance().add_project())
def test_create_shape(http_controller, tmpdir, project, async_run):
def test_create_drawing(http_controller, tmpdir, project, async_run):
response = http_controller.post("/projects/{}/shapes".format(project.id), {
response = http_controller.post("/projects/{}/drawings".format(project.id), {
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
}, example=True)
assert response.status == 201
assert response.json["shape_id"] is not None
assert response.json["drawing_id"] is not None
def test_update_shape(http_controller, tmpdir, project, async_run):
def test_update_drawing(http_controller, tmpdir, project, async_run):
response = http_controller.post("/projects/{}/shapes".format(project.id), {
response = http_controller.post("/projects/{}/drawings".format(project.id), {
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
},)
response = http_controller.put("/projects/{}/shapes/{}".format(project.id, response.json["shape_id"]), {
response = http_controller.put("/projects/{}/drawings/{}".format(project.id, response.json["drawing_id"]), {
"x": 42,
}, example=True)
assert response.status == 201
assert response.json["x"] == 42
def test_list_shape(http_controller, tmpdir, project, async_run):
response = http_controller.post("/projects/{}/shapes".format(project.id), {
def test_list_drawing(http_controller, tmpdir, project, async_run):
response = http_controller.post("/projects/{}/drawings".format(project.id), {
"svg": '<svg height="210" width="500"><line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,0,0);stroke-width:2" /></svg>',
"x": 10,
"y": 20,
"z": 0
}, example=False)
response = http_controller.get("/projects/{}/shapes".format(project.id), example=True)
response = http_controller.get("/projects/{}/drawings".format(project.id), example=True)
assert response.status == 200
assert len(response.json) == 1
def test_delete_shape(http_controller, tmpdir, project, async_run):
def test_delete_drawing(http_controller, tmpdir, project, async_run):
shape = Shape(project)
project._shapes = {shape.id: shape}
response = http_controller.delete("/projects/{}/shapes/{}".format(project.id, shape.id), example=True)
drawing = Drawing(project)
project._drawings = {drawing.id: drawing}
response = http_controller.delete("/projects/{}/drawings/{}".format(project.id, drawing.id), example=True)
assert response.status == 204
assert shape.id not in project._shapes
assert drawing.id not in project._drawings