Use Pydantic to validate the server config file.

This commit is contained in:
grossmj committed 2021-04-12 17:02:23 +09:30
1 parent 478119b40d
commit 30ebae207f
61 files changed
+871 -695

No files matched your search

@@ -37,19 +37,20 @@ async def manager(port_manager):
return m
def test_vm_invalid_dynamips_path(manager):
def test_vm_invalid_dynamips_path(manager, config):
with patch("gns3server.config.Config.get_section_config", return_value={"dynamips_path": "/bin/test_fake"}):
with pytest.raises(DynamipsError):
manager.find_dynamips()
config.settings.Dynamips.dynamips_path = "/bin/test_fake"
with pytest.raises(DynamipsError):
manager.find_dynamips()
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported by Windows")
def test_vm_non_executable_dynamips_path(manager):
def test_vm_non_executable_dynamips_path(manager, config):
tmpfile = tempfile.NamedTemporaryFile()
with patch("gns3server.config.Config.get_section_config", return_value={"dynamips_path": tmpfile.name}):
with pytest.raises(DynamipsError):
manager.find_dynamips()
config.settings.Dynamips.dynamips_path = tmpfile.name
with pytest.raises(DynamipsError):
manager.find_dynamips()
def test_get_dynamips_id(manager):
@@ -66,11 +66,11 @@ def test_convert_project_before_2_0_0_b3(compute_project, manager):
@pytest.mark.asyncio
async def test_router_invalid_dynamips_path(compute_project, manager):
async def test_router_invalid_dynamips_path(compute_project, config, manager):
config = Config.instance()
config.set("Dynamips", "dynamips_path", "/bin/test_fake")
config.set("Dynamips", "allocate_aux_console_ports", False)
config.settings.Dynamips.dynamips_path = "/bin/test_fake"
config.settings.Dynamips.allocate_aux_console_ports = False
with pytest.raises(DynamipsError):
router = Router("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", compute_project, manager)