1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix tests

This commit is contained in:
Julien Duponchelle 2015-01-20 09:58:58 +01:00
parent 7fff25a9a9
commit 927e6b540d
5 changed files with 19 additions and 18 deletions

View File

@ -1,4 +1,4 @@
curl -i -xGET 'http://localhost:8000/version' curl -i -X GET 'http://localhost:8000/version'
GET /version HTTP/1.1 GET /version HTTP/1.1

View File

@ -1,8 +1,8 @@
curl -i -xPOST 'http://localhost:8000/project' -d '{"location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-253/test_create_project_with_dir0"}' curl -i -X POST 'http://localhost:8000/project' -d '{"location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-262/test_create_project_with_dir0"}'
POST /project HTTP/1.1 POST /project HTTP/1.1
{ {
"location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-253/test_create_project_with_dir0" "location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-262/test_create_project_with_dir0"
} }
@ -15,6 +15,6 @@ SERVER: Python/3.4 aiohttp/0.13.1
X-ROUTE: /project X-ROUTE: /project
{ {
"location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-253/test_create_project_with_dir0", "location": "/private/var/folders/3s/r2wbv07n7wg4vrsn874lmxxh0000gn/T/pytest-262/test_create_project_with_dir0",
"uuid": "a8984692-a820-45de-8d4d-fc006b29072a" "uuid": "66821e79-aa05-4490-8c26-ffb7aeddc0d2"
} }

View File

@ -1,4 +1,4 @@
curl -i -xPOST 'http://localhost:8000/version' -d '{"version": "1.3.dev1"}' curl -i -X POST 'http://localhost:8000/version' -d '{"version": "1.3.dev1"}'
POST /version HTTP/1.1 POST /version HTTP/1.1
{ {

View File

@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from tests.api.base import server, loop
from tests.utils import asyncio_patch from tests.utils import asyncio_patch
from unittest.mock import patch from unittest.mock import patch

View File

@ -36,27 +36,27 @@ def manager():
@patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.6".encode("utf-8")) @patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.6".encode("utf-8"))
def test_vm(tmpdir, manager): def test_vm(tmpdir, manager):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", manager, working_dir=str(tmpdir))
assert vm.name == "test" assert vm.name == "test"
assert vm.id == 42 assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
@patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.1".encode("utf-8")) @patch("subprocess.check_output", return_value="Welcome to Virtual PC Simulator, version 0.1".encode("utf-8"))
def test_vm_invalid_vpcs_version(tmpdir, manager): def test_vm_invalid_vpcs_version(tmpdir, manager):
with pytest.raises(VPCSError): with pytest.raises(VPCSError):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", manager, working_dir=str(tmpdir))
assert vm.name == "test" assert vm.name == "test"
assert vm.id == 42 assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
@patch("gns3server.config.Config.get_section_config", return_value = {"path": "/bin/test_fake"}) @patch("gns3server.config.Config.get_section_config", return_value = {"path": "/bin/test_fake"})
def test_vm_invalid_vpcs_path(tmpdir, manager): def test_vm_invalid_vpcs_path(tmpdir, manager):
with pytest.raises(VPCSError): with pytest.raises(VPCSError):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", manager, working_dir=str(tmpdir))
assert vm.name == "test" assert vm.name == "test"
assert vm.id == 42 assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
def test_start(tmpdir, loop, manager): def test_start(tmpdir, loop, manager):
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()): with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", 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"})
loop.run_until_complete(asyncio.async(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
@ -65,7 +65,7 @@ def test_start(tmpdir, loop, manager):
def test_stop(tmpdir, loop, manager): def test_stop(tmpdir, loop, manager):
process = MagicMock() process = MagicMock()
with asyncio_patch("asyncio.create_subprocess_exec", return_value=process): with asyncio_patch("asyncio.create_subprocess_exec", return_value=process):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", 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"})
loop.run_until_complete(asyncio.async(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
@ -75,25 +75,25 @@ def test_stop(tmpdir, loop, manager):
process.terminate.assert_called_with() process.terminate.assert_called_with()
def test_add_nio_binding_udp(tmpdir, manager): def test_add_nio_binding_udp(tmpdir, manager):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", 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"})
assert nio.lport == 4242 assert nio.lport == 4242
def test_add_nio_binding_tap(tmpdir, manager): def test_add_nio_binding_tap(tmpdir, manager):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", manager, working_dir=str(tmpdir))
with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=True): with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=True):
nio = vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"}) nio = vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"})
assert nio.tap_device == "test" assert nio.tap_device == "test"
def test_add_nio_binding_tap_no_privileged_access(tmpdir, manager): def test_add_nio_binding_tap_no_privileged_access(tmpdir, manager):
vm = VPCSDevice("test", 42, manager, working_dir=str(tmpdir)) vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", manager, working_dir=str(tmpdir))
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 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", "00010203-0405-0607-0809-0a0b0c0d0e0f", 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] is None assert vm._ethernet_adapter.ports[0] is None