mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
PEP8
This commit is contained in:
1 parent
0695e75e77
commit
68d0e5f42d
18 files changed
+49
-64
No files matched your search
@@ -19,7 +19,7 @@ import pytest
|
||||
import asyncio
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
#TODO: Move loop to util
|
||||
# TODO: Move loop to util
|
||||
from tests.api.base import loop, project
|
||||
from asyncio.subprocess import Process
|
||||
from unittest.mock import patch, MagicMock
|
||||
@@ -42,6 +42,7 @@ def test_vm(manager):
|
||||
assert vm.name == "test"
|
||||
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"))
|
||||
def test_vm_invalid_vpcs_version(project, manager):
|
||||
with pytest.raises(VPCSError):
|
||||
@@ -49,20 +50,23 @@ def test_vm_invalid_vpcs_version(project, manager):
|
||||
assert vm.name == "test"
|
||||
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(project, manager):
|
||||
with pytest.raises(VPCSError):
|
||||
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
assert vm.name == "test"
|
||||
assert vm.uuid == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
def test_start(project, loop, manager):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
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()))
|
||||
assert vm.is_running() == True
|
||||
assert vm.is_running()
|
||||
|
||||
|
||||
def test_stop(project, loop, manager):
|
||||
process = MagicMock()
|
||||
@@ -71,22 +75,25 @@ def test_stop(project, loop, manager):
|
||||
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()))
|
||||
assert vm.is_running() == True
|
||||
assert vm.is_running()
|
||||
loop.run_until_complete(asyncio.async(vm.stop()))
|
||||
assert vm.is_running() == False
|
||||
assert vm.is_running() is False
|
||||
process.terminate.assert_called_with()
|
||||
|
||||
|
||||
def test_add_nio_binding_udp(manager):
|
||||
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
assert nio.lport == 4242
|
||||
|
||||
|
||||
def test_add_nio_binding_tap(project, manager):
|
||||
vm = VPCSDevice("test", 42, project, manager)
|
||||
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"})
|
||||
assert nio.tap_device == "test"
|
||||
|
||||
|
||||
def test_add_nio_binding_tap_no_privileged_access(manager):
|
||||
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
with patch("gns3server.modules.vpcs.vpcs_device.has_privileged_access", return_value=False):
|
||||
@@ -94,6 +101,7 @@ def test_add_nio_binding_tap_no_privileged_access(manager):
|
||||
vm.port_add_nio_binding(0, {"type": "nio_tap", "tap_device": "test"})
|
||||
assert vm._ethernet_adapter.ports[0] is None
|
||||
|
||||
|
||||
def test_port_remove_nio_binding(manager):
|
||||
vm = VPCSDevice("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager)
|
||||
nio = vm.port_add_nio_binding(0, {"type": "nio_udp", "lport": 4242, "rport": 4243, "rhost": "127.0.0.1"})
|
||||
|
||||
Reference in new issue
Block a user