diff --git a/gns3server/handlers/api/controller/drawing_handler.py b/gns3server/handlers/api/controller/drawing_handler.py index 48af0c53..719b2694 100644 --- a/gns3server/handlers/api/controller/drawing_handler.py +++ b/gns3server/handlers/api/controller/drawing_handler.py @@ -61,6 +61,26 @@ class DrawingHandler: response.set_status(201) response.json(drawing) + @Route.get( + r"/projects/{project_id}/drawings/{drawing_id}", + parameters={ + "project_id": "Project UUID", + "drawing_id": "Drawing UUID" + }, + status_codes={ + 200: "Drawing found", + 400: "Invalid request", + 404: "Drawing doesn't exist" + }, + description="Get a drawing instance", + output=DRAWING_OBJECT_SCHEMA) + def get_drawing(request, response): + + project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"]) + drawing = project.get_drawing(request.match_info["drawing_id"]) + response.set_status(200) + response.json(drawing) + @Route.put( r"/projects/{project_id}/drawings/{drawing_id}", parameters={ @@ -71,7 +91,7 @@ class DrawingHandler: 201: "Drawing updated", 400: "Invalid request" }, - description="Create a new drawing instance", + description="Update a drawing instance", input=DRAWING_OBJECT_SCHEMA, output=DRAWING_OBJECT_SCHEMA) def update(request, response): diff --git a/gns3server/handlers/api/controller/link_handler.py b/gns3server/handlers/api/controller/link_handler.py index 96d89cfc..48e394cb 100644 --- a/gns3server/handlers/api/controller/link_handler.py +++ b/gns3server/handlers/api/controller/link_handler.py @@ -97,6 +97,26 @@ class LinkHandler: response.set_status(200) response.json(link.available_filters()) + @Route.get( + r"/projects/{project_id}/links/{link_id}", + parameters={ + "project_id": "Project UUID", + "link_id": "Link UUID" + }, + status_codes={ + 200: "Link found", + 400: "Invalid request", + 404: "Link doesn't exist" + }, + description="Get a link instance", + output=LINK_OBJECT_SCHEMA) + def get_link(request, response): + + project = yield from Controller.instance().get_loaded_project(request.match_info["project_id"]) + link = project.get_link(request.match_info["link_id"]) + response.set_status(200) + response.json(link) + @Route.put( r"/projects/{project_id}/links/{link_id}", parameters={ diff --git a/tests/handlers/api/controller/test_drawing.py b/tests/handlers/api/controller/test_drawing.py index ca5f899b..07070c11 100644 --- a/tests/handlers/api/controller/test_drawing.py +++ b/tests/handlers/api/controller/test_drawing.py @@ -50,6 +50,19 @@ def test_create_drawing(http_controller, tmpdir, project, async_run): assert response.json["drawing_id"] is not None +def test_get_drawing(http_controller, tmpdir, project, async_run): + + response = http_controller.post("/projects/{}/drawings".format(project.id), { + "svg": '', + "x": 10, + "y": 20, + "z": 0 + },) + response = http_controller.get("/projects/{}/drawings/{}".format(project.id, response.json["drawing_id"]), example=True) + assert response.status == 200 + assert response.json["x"] == 10 + + def test_update_drawing(http_controller, tmpdir, project, async_run): response = http_controller.post("/projects/{}/drawings".format(project.id), { diff --git a/tests/handlers/api/controller/test_link.py b/tests/handlers/api/controller/test_link.py index 319e3dc3..7a938d4f 100644 --- a/tests/handlers/api/controller/test_link.py +++ b/tests/handlers/api/controller/test_link.py @@ -128,6 +128,43 @@ def test_create_link_failure(http_controller, tmpdir, project, compute, async_ru assert len(project.links) == 0 +def test_get_link(http_controller, tmpdir, project, compute, async_run): + response = MagicMock() + response.json = {"console": 2048} + compute.post = AsyncioMagicMock(return_value=response) + + node1 = async_run(project.add_node(compute, "node1", None, node_type="qemu")) + node1._ports = [EthernetPort("E0", 0, 0, 3)] + node2 = async_run(project.add_node(compute, "node2", None, node_type="qemu")) + node2._ports = [EthernetPort("E0", 0, 2, 4)] + + with asyncio_patch("gns3server.controller.udp_link.UDPLink.create"): + response = http_controller.post("/projects/{}/links".format(project.id), { + "nodes": [ + { + "node_id": node1.id, + "adapter_number": 0, + "port_number": 3, + "label": { + "text": "Text", + "x": 42, + "y": 0 + } + }, + { + "node_id": node2.id, + "adapter_number": 2, + "port_number": 4 + } + ] + }) + link_id = response.json["link_id"] + assert response.json["nodes"][0]["label"]["x"] == 42 + response = http_controller.get("/projects/{}/links/{}".format(project.id, link_id), example=True) + assert response.status == 200 + assert response.json["nodes"][0]["label"]["x"] == 42 + + def test_update_link_suspend(http_controller, tmpdir, project, compute, async_run): response = MagicMock() response.json = {"console": 2048} @@ -242,7 +279,7 @@ def test_update_link(http_controller, tmpdir, project, compute, async_run): } ], "filters": filters - }) + }, example=True) assert response.status == 201 assert response.json["nodes"][0]["label"]["x"] == 64 assert list(project.links.values())[0].filters == filters