API for deleting a list

This commit is contained in:
Julien Duponchelle committed 2016-03-14 17:40:27 +01:00
1 parent 9771b33b68
commit 9062490be3
7 files changed
+105 -8

No files matched your search

+19
View File
@@ -17,6 +17,7 @@
import pytest
import asyncio
import aiohttp
from unittest.mock import MagicMock
from gns3server.controller.project import Project
@@ -79,3 +80,21 @@ def test_create(async_run, project):
"rport": 1024,
"type": "nio_udp"
})
def test_delete(async_run, project):
hypervisor1 = MagicMock()
hypervisor2 = MagicMock()
vm1 = VM(project, hypervisor1, vm_type="vpcs")
vm2 = VM(project, hypervisor2, vm_type="vpcs")
link = UDPLink(project)
async_run(link.addVM(vm1, 0, 4))
async_run(link.addVM(vm2, 3, 1))
async_run(link.delete())
hypervisor1.delete.assert_any_call("/projects/{}/vpcs/vms/{}/adapters/0/ports/4/nio".format(project.id, vm1.id))
hypervisor2.delete.assert_any_call("/projects/{}/vpcs/vms/{}/adapters/3/ports/1/nio".format(project.id, vm2.id))
+5
View File
@@ -78,3 +78,8 @@ def test_create(vm, hypervisor, project, async_run):
def test_post(vm, hypervisor, async_run):
async_run(vm.post("/test", {"a": "b"}))
hypervisor.post.assert_called_with("/projects/{}/vpcs/vms/{}/test".format(vm.project.id, vm.id), data={"a": "b"})
def test_delete(vm, hypervisor, async_run):
async_run(vm.delete("/test"))
hypervisor.delete.assert_called_with("/projects/{}/vpcs/vms/{}/test".format(vm.project.id, vm.id))
+12 -2
View File
@@ -32,6 +32,7 @@ from tests.utils import asyncio_patch
from gns3server.handlers.api.controller.project_handler import ProjectHandler
from gns3server.controller import Controller
from gns3server.controller.vm import VM
from gns3server.controller.link import Link
@pytest.fixture
@@ -51,8 +52,7 @@ def test_create_link(http_controller, tmpdir, project, hypervisor, async_run):
vm1 = async_run(project.addVM(hypervisor, None))
vm2 = async_run(project.addVM(hypervisor, None))
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create"):
with asyncio_patch("gns3server.controller.udp_link.UDPLink.create") as mock:
response = http_controller.post("/projects/{}/links".format(project.id), {
"vms": [
{
@@ -67,6 +67,16 @@ def test_create_link(http_controller, tmpdir, project, hypervisor, async_run):
}
]
}, example=True)
assert mock.called
assert response.status == 201
assert response.json["link_id"] is not None
assert len(response.json["vms"]) == 2
def test_delete_link(http_controller, tmpdir, project, hypervisor, async_run):
link = Link(project)
project._links = {link.id: link}
with asyncio_patch("gns3server.controller.udp_link.Link.delete"):
response = http_controller.delete("/projects/{}/links/{}".format(project.id, link.id), example=True)
assert response.status == 201