mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-26 00:38:10 +00:00
Merge pull request #1252 from ehlers/api_links_drawings
GNS3-API: implement GET for specific drawing and link
This commit is contained in:
commit
266916b092
@ -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):
|
||||
|
@ -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={
|
||||
|
@ -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": '<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.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), {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user