mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Fixes tests.
This commit is contained in:
1 parent
25b778aec0
commit
6d56da03e5
8 files changed
+53
-46
No files matched your search
@@ -44,10 +44,7 @@ def test_router(project, manager):
|
||||
|
||||
|
||||
def test_router_invalid_dynamips_path(project, manager, loop):
|
||||
config = configparser.ConfigParser()
|
||||
config.add_section("Dynamips")
|
||||
config.set("Dynamips", "dynamips_path", "/bin/test_fake")
|
||||
with patch("gns3server.config.Config", return_value=config):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"dynamips_path": "/bin/test_fake"}):
|
||||
with pytest.raises(DynamipsError):
|
||||
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
|
||||
loop.run_until_complete(asyncio.async(router.create()))
|
||||
|
||||
@@ -85,11 +85,12 @@ def test_vm_invalid_iouyap_path(project, manager, loop):
|
||||
def test_start(loop, vm, monkeypatch):
|
||||
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running()
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()):
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running()
|
||||
|
||||
|
||||
def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
||||
@@ -100,13 +101,14 @@ def test_start_with_iourc(loop, vm, monkeypatch, tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"iourc_path": fake_file, "iouyap_path": vm.iouyap_path}):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_requirements", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running()
|
||||
arsgs, kwargs = exec_mock.call_args
|
||||
assert kwargs["env"]["IOURC"] == fake_file
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._check_iou_licence", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_ioucon", return_value=True):
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM._start_iouyap", return_value=True):
|
||||
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as exec_mock:
|
||||
loop.run_until_complete(asyncio.async(vm.start()))
|
||||
assert vm.is_running()
|
||||
arsgs, kwargs = exec_mock.call_args
|
||||
assert kwargs["env"]["IOURC"] == fake_file
|
||||
|
||||
|
||||
def test_rename_nvram_file(loop, vm, monkeypatch):
|
||||
|
||||
@@ -60,7 +60,7 @@ def test_create_vm_new_topology_without_uuid(loop, project, port_manager):
|
||||
|
||||
def test_create_vm_old_topology(loop, project, tmpdir, port_manager):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
# Create an old topology directory
|
||||
project_dir = str(tmpdir / "testold")
|
||||
vm_dir = os.path.join(project_dir, "testold-files", "vpcs", "pc-1")
|
||||
|
||||
@@ -20,7 +20,6 @@ import os
|
||||
import asyncio
|
||||
import pytest
|
||||
import aiohttp
|
||||
import shutil
|
||||
from uuid import uuid4
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -51,7 +50,7 @@ def test_affect_uuid():
|
||||
|
||||
|
||||
def test_path(tmpdir):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.path == os.path.join(str(tmpdir), p.id)
|
||||
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
||||
@@ -60,14 +59,14 @@ def test_path(tmpdir):
|
||||
|
||||
def test_init_path(tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
p = Project(path=str(tmpdir))
|
||||
assert p.path == str(tmpdir)
|
||||
|
||||
|
||||
def test_changing_path_temporary_flag(tmpdir):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
p = Project(temporary=True)
|
||||
assert os.path.exists(p.path)
|
||||
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
@@ -96,13 +95,13 @@ def test_remove_temporary_flag():
|
||||
|
||||
|
||||
def test_changing_location_not_allowed(tmpdir):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": False}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
p = Project(location=str(tmpdir))
|
||||
|
||||
|
||||
def test_changing_path_not_allowed(tmpdir):
|
||||
with patch("gns3server.config.Config.getboolean", return_value=False):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
p = Project()
|
||||
p.path = str(tmpdir)
|
||||
@@ -110,11 +109,11 @@ def test_changing_path_not_allowed(tmpdir):
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project()
|
||||
assert p.__json__() == {"location": p.location, "path": p.path, "project_id": p.id, "temporary": False}
|
||||
assert p.__json__() == {"name": p.name, "location": p.location, "path": p.path, "project_id": p.id, "temporary": False}
|
||||
|
||||
|
||||
def test_vm_working_directory(tmpdir, vm):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
with patch("gns3server.modules.project.Project.is_local", return_value=True):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.vm_working_directory(vm) == os.path.join(str(tmpdir), p.id, 'project-files', vm.module_name, vm.id)
|
||||
assert os.path.exists(p.vm_working_directory(vm))
|
||||
|
||||
Reference in new issue
Block a user