1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Fix tests

This commit is contained in:
Julien Duponchelle 2015-01-19 11:28:51 +01:00
parent 73a481e510
commit 7de95cd60a
4 changed files with 46 additions and 6 deletions

View File

@ -0,0 +1,15 @@
curl -i -xDELETE 'http://localhost:8000/vpcs/{id:\d+}/ports/{port_id}/nio'
DELETE /vpcs/{id:\d+}/ports/{port_id}/nio HTTP/1.1
HTTP/1.1 200
CONNECTION: close
CONTENT-LENGTH: 2
CONTENT-TYPE: application/json
DATE: Thu, 08 Jan 2015 16:09:15 GMT
SERVER: Python/3.4 aiohttp/0.13.1
X-ROUTE: /vpcs/{id:\d+}/ports/{port_id}/nio
{}

View File

@ -0,0 +1,25 @@
curl -i -xPOST 'http://localhost:8000/vpcs/{id:\d+}/ports/{port_id}/nio' -d '{"lport": 4242, "rhost": "127.0.0.1", "rport": 4343, "type": "nio_udp"}'
POST /vpcs/{id:\d+}/ports/{port_id}/nio HTTP/1.1
{
"lport": 4242,
"rhost": "127.0.0.1",
"rport": 4343,
"type": "nio_udp"
}
HTTP/1.1 200
CONNECTION: close
CONTENT-LENGTH: 89
CONTENT-TYPE: application/json
DATE: Thu, 08 Jan 2015 16:09:15 GMT
SERVER: Python/3.4 aiohttp/0.13.1
X-ROUTE: /vpcs/{id:\d+}/ports/{port_id}/nio
{
"lport": 4242,
"rhost": "127.0.0.1",
"rport": 4343,
"type": "nio_udp"
}

View File

@ -39,7 +39,7 @@ def test_vpcs_nio_create_udp(server):
}, },
example=True) example=True)
assert response.status == 200 assert response.status == 200
assert response.route == '/vpcs/{id}/ports/{port_id}/nio' assert response.route == '/vpcs/{id:\d+}/ports/{port_id}/nio'
assert response.json['type'] == 'nio_udp' assert response.json['type'] == 'nio_udp'
@patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=True) @patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=True)
@ -50,7 +50,7 @@ def test_vpcs_nio_create_tap(mock, server):
'tap_device': 'test', 'tap_device': 'test',
}) })
assert response.status == 200 assert response.status == 200
assert response.route == '/vpcs/{vpcs_id}/ports/{port_id}/nio' assert response.route == '/vpcs/{id:\d+}/ports/{port_id}/nio'
assert response.json['type'] == 'nio_tap' assert response.json['type'] == 'nio_tap'
def test_vpcs_delete_nio(server): def test_vpcs_delete_nio(server):
@ -62,8 +62,8 @@ def test_vpcs_delete_nio(server):
'rhost': '127.0.0.1' 'rhost': '127.0.0.1'
}, },
) )
response = server.delete('/vpcs/{}/ports/0/nio'.format(vm.json["vpcs_id"]), example=True) response = server.delete('/vpcs/{}/ports/0/nio'.format(vm.json["id"]), example=True)
assert response.status == 200 assert response.status == 200
assert response.route == '/vpcs/{id}/ports/{port_id}/nio' assert response.route == '/vpcs/{id:\d+}/ports/{port_id}/nio'

View File

@ -90,10 +90,10 @@ def test_add_nio_binding_tap_no_privileged_access(tmpdir, manager):
with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=False): with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=False):
with pytest.raises(VPCSError): with pytest.raises(VPCSError):
vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"}) vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"})
assert vm._ethernet_adapter.ports[0] is not None assert vm._ethernet_adapter.ports[0] is None
def test_port_remove_nio_binding(tmpdir, manager): def test_port_remove_nio_binding(tmpdir, manager):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir))
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"}) nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
vm.port_remove_nio_binding(0) vm.port_remove_nio_binding(0)
assert vm._ethernet_adapter.ports[0] == None assert vm._ethernet_adapter.ports[0] is None