mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-22 14:12:29 +00:00
Add an endpoint for listing the links of a project
This commit is contained in:
parent
ce0d715895
commit
b07dcf552c
@ -31,6 +31,21 @@ class LinkHandler:
|
|||||||
API entry point for Link
|
API entry point for Link
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@Route.get(
|
||||||
|
r"/projects/{project_id}/links",
|
||||||
|
parameters={
|
||||||
|
"project_id": "Project UUID"
|
||||||
|
},
|
||||||
|
status_codes={
|
||||||
|
200: "List of links returned",
|
||||||
|
},
|
||||||
|
description="List links of a project")
|
||||||
|
def list_links(request, response):
|
||||||
|
|
||||||
|
controller = Controller.instance()
|
||||||
|
project = controller.get_project(request.match_info["project_id"])
|
||||||
|
response.json([v for v in project.links.values()])
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
r"/projects/{project_id}/links",
|
r"/projects/{project_id}/links",
|
||||||
parameters={
|
parameters={
|
||||||
|
@ -77,6 +77,34 @@ def test_create_link(http_controller, tmpdir, project, compute, async_run):
|
|||||||
assert len(response.json["nodes"]) == 2
|
assert len(response.json["nodes"]) == 2
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_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, None))
|
||||||
|
node2 = async_run(project.add_node(compute, None))
|
||||||
|
|
||||||
|
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
|
||||||
|
response = http_controller.post("/projects/{}/links".format(project.id), {
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"node_id": node1.id,
|
||||||
|
"adapter_number": 0,
|
||||||
|
"port_number": 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"node_id": node2.id,
|
||||||
|
"adapter_number": 2,
|
||||||
|
"port_number": 4
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
response = http_controller.get("/projects/{}/links".format(project.id), example=True)
|
||||||
|
assert response.status == 200
|
||||||
|
assert len(response.json) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_start_capture(http_controller, tmpdir, project, compute, async_run):
|
def test_start_capture(http_controller, tmpdir, project, compute, async_run):
|
||||||
link = Link(project)
|
link = Link(project)
|
||||||
project._links = {link.id: link}
|
project._links = {link.id: link}
|
||||||
|
Loading…
Reference in New Issue
Block a user