Update tests.

This commit is contained in:
Jeremy 2015-01-23 16:38:59 -07:00
parent 6460e94311
commit 499a8f10ae
5 changed files with 60 additions and 27 deletions

View File

@ -22,8 +22,8 @@ from tests.utils import asyncio_patch
@pytest.fixture(scope="module")
def vm(server, project):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.create", return_value=True) as mock:
response = server.post("/virtualbox", {"name": "VM1",
"vmname": "VM1",
response = server.post("/virtualbox", {"name": "VMTEST",
"vmname": "VMTEST",
"linked_clone": False,
"project_uuid": project.uuid})
assert mock.called
@ -44,6 +44,14 @@ def test_vbox_create(server, project):
assert response.json["project_uuid"] == project.uuid
def test_vbox_get(server, project, vm):
response = server.get("/virtualbox/{}".format(vm["uuid"]), example=True)
assert response.status == 200
assert response.route == "/virtualbox/{uuid}"
assert response.json["name"] == "VMTEST"
assert response.json["project_uuid"] == project.uuid
def test_vbox_start(server, vm):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM.start", return_value=True) as mock:
response = server.post("/virtualbox/{}/start".format(vm["uuid"]))
@ -77,3 +85,32 @@ def test_vbox_reload(server, vm):
response = server.post("/virtualbox/{}/reload".format(vm["uuid"]))
assert mock.called
assert response.status == 204
def test_vbox_nio_create_udp(server, vm):
response = server.post("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"},
example=True)
assert response.status == 201
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
assert response.json["type"] == "nio_udp"
def test_vbox_delete_nio(server, vm):
server.post("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"})
response = server.delete("/virtualbox/{}/ports/0/nio".format(vm["uuid"]), example=True)
assert response.status == 204
assert response.route == "/virtualbox/{uuid}/ports/{port_id:\d+}/nio"
def test_vpcs_update(server, vm, free_console_port):
response = server.put("/virtualbox/{}".format(vm["uuid"]), {"name": "test",
"console": free_console_port})
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["console"] == free_console_port

View File

@ -82,7 +82,7 @@ def test_vpcs_nio_create_udp(server, vm):
"rhost": "127.0.0.1"},
example=True)
assert response.status == 201
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
assert response.json["type"] == "nio_udp"
@ -91,18 +91,18 @@ def test_vpcs_nio_create_tap(server, vm):
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_tap",
"tap_device": "test"})
assert response.status == 201
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
assert response.json["type"] == "nio_tap"
def test_vpcs_delete_nio(server, vm):
response = server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
server.post("/vpcs/{}/ports/0/nio".format(vm["uuid"]), {"type": "nio_udp",
"lport": 4242,
"rport": 4343,
"rhost": "127.0.0.1"})
response = server.delete("/vpcs/{}/ports/0/nio".format(vm["uuid"]), example=True)
assert response.status == 204
assert response.route == "/vpcs/{uuid}/ports/{port_id}/nio"
assert response.route == "/vpcs/{uuid}/ports/{port_id:\d+}/nio"
def test_vpcs_start(server, vm):

View File

@ -91,7 +91,7 @@ def project():
def port_manager():
"""An instance of port manager"""
return PortManager("127.0.0.1", False)
return PortManager("127.0.0.1")
@pytest.fixture(scope="function")

View File

@ -45,8 +45,8 @@ def test_affect_uuid():
assert p.uuid == '00010203-0405-0607-0809-0a0b0c0d0e0f'
@patch("gns3server.config.Config.get_section_config", return_value={"local": True})
def test_path(tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
p = Project(location=str(tmpdir))
assert p.path == os.path.join(str(tmpdir), p.uuid)
assert os.path.exists(os.path.join(str(tmpdir), p.uuid))
@ -58,8 +58,8 @@ def test_temporary_path():
assert os.path.exists(p.path)
@patch("gns3server.config.Config.get_section_config", return_value={"local": False})
def test_changing_location_not_allowed(mock, tmpdir):
def test_changing_location_not_allowed(tmpdir):
with patch("gns3server.config.Config.get_section_config", return_value={"local": False}):
with pytest.raises(aiohttp.web.HTTPForbidden):
p = Project(location=str(tmpdir))
@ -69,8 +69,8 @@ def test_json(tmpdir):
assert p.__json__() == {"location": p.location, "uuid": p.uuid, "temporary": False}
@patch("gns3server.config.Config.get_section_config", return_value={"local": True})
def test_vm_working_directory(tmpdir, vm):
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
p = Project(location=str(tmpdir))
assert os.path.exists(p.vm_working_directory(vm))
assert os.path.exists(os.path.join(str(tmpdir), p.uuid, vm.module_name, vm.uuid))

View File

@ -60,7 +60,6 @@ def test_vm_non_executable_vboxmanage_path(project, manager, loop):
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager, "test", False)
vm._find_vboxmanage()
def test_vm_valid_virtualbox_api_version(loop, project, manager):
with asyncio_patch("gns3server.modules.virtualbox.virtualbox_vm.VirtualBoxVM._execute", return_value=["API version: 4_3"]):
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
@ -72,6 +71,3 @@ def test_vm_invalid_virtualbox_api_version(loop, project, manager):
with pytest.raises(VirtualBoxError):
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
loop.run_until_complete(asyncio.async(vm.create()))
# TODO: find a way to test start, stop, suspend, resume and reload