From 7de95cd60a70ef4bd09f26fb63961cfa888e50e3 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 19 Jan 2015 11:28:51 +0100 Subject: [PATCH] Fix tests --- .../examples/delete_vpcsiddportsportidnio.txt | 15 +++++++++++ .../examples/post_vpcsiddportsportidnio.txt | 25 +++++++++++++++++++ tests/api/test_vpcs.py | 8 +++--- tests/modules/vpcs/test_vpcs_device.py | 4 +-- 4 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 docs/api/examples/delete_vpcsiddportsportidnio.txt create mode 100644 docs/api/examples/post_vpcsiddportsportidnio.txt diff --git a/docs/api/examples/delete_vpcsiddportsportidnio.txt b/docs/api/examples/delete_vpcsiddportsportidnio.txt new file mode 100644 index 00000000..6cb18d74 --- /dev/null +++ b/docs/api/examples/delete_vpcsiddportsportidnio.txt @@ -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 + +{} diff --git a/docs/api/examples/post_vpcsiddportsportidnio.txt b/docs/api/examples/post_vpcsiddportsportidnio.txt new file mode 100644 index 00000000..771255e0 --- /dev/null +++ b/docs/api/examples/post_vpcsiddportsportidnio.txt @@ -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" +} diff --git a/tests/api/test_vpcs.py b/tests/api/test_vpcs.py index cc2f47f5..9dbbf94c 100644 --- a/tests/api/test_vpcs.py +++ b/tests/api/test_vpcs.py @@ -39,7 +39,7 @@ def test_vpcs_nio_create_udp(server): }, example=True) 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' @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', }) 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' def test_vpcs_delete_nio(server): @@ -62,8 +62,8 @@ def test_vpcs_delete_nio(server): '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.route == '/vpcs/{id}/ports/{port_id}/nio' + assert response.route == '/vpcs/{id:\d+}/ports/{port_id}/nio' diff --git a/tests/modules/vpcs/test_vpcs_device.py b/tests/modules/vpcs/test_vpcs_device.py index 57eb374d..3d532f1a 100644 --- a/tests/modules/vpcs/test_vpcs_device.py +++ b/tests/modules/vpcs/test_vpcs_device.py @@ -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 pytest.raises(VPCSError): 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): 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"}) vm.port_remove_nio_binding(0) - assert vm._ethernet_adapter.ports[0] == None + assert vm._ethernet_adapter.ports[0] is None