1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-23 23:38:21 +00:00

Fix tests running on Python 3.12

This commit is contained in:
grossmj 2023-10-23 16:12:12 +10:00
parent 4af5edbc03
commit 34ee75e1f1
2 changed files with 15 additions and 14 deletions

View File

@ -208,18 +208,18 @@ async def test_termination_callback_error(vm, tmpdir):
async def test_reload(vm):
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as mock:
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as m:
await vm.reload()
assert mock.called_with("system_reset")
m.assert_called_with("system_reset")
async def test_suspend(vm):
async def test_suspend(vm, running_subprocess_mock):
control_vm_result = MagicMock()
control_vm_result.match.group.decode.return_value = "running"
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm", return_value=control_vm_result) as mock:
await vm.suspend()
assert mock.called_with("system_reset")
vm._process = running_subprocess_mock
with asyncio_patch("gns3server.compute.qemu.QemuVM._get_vm_status", return_value="running"):
with asyncio_patch("gns3server.compute.qemu.QemuVM._control_vm") as m:
await vm.suspend()
m.assert_called_with("stop")
async def test_add_nio_binding_udp(vm):
@ -490,14 +490,15 @@ def test_json(vm, compute_project):
assert json["project_id"] == compute_project.id
async def test_control_vm(vm):
async def test_control_vm(vm, running_subprocess_mock):
vm._process = MagicMock()
vm._process = running_subprocess_mock
vm._monitor = 4242
reader = MagicMock()
writer = MagicMock()
with asyncio_patch("asyncio.open_connection", return_value=(reader, writer)):
res = await vm._control_vm("test")
assert writer.write.called_with("test")
writer.write.assert_called_with(b"test\n")
assert res is None
@ -514,7 +515,7 @@ async def test_control_vm_expect_text(vm, running_subprocess_mock):
vm._monitor = 4242
res = await vm._control_vm("test", [b"epic"])
assert writer.write.called_with("test")
writer.write.assert_called_with(b"test\n")
assert res == "epic product"

View File

@ -255,7 +255,7 @@ async def test_qemu_list_binaries(compute_api, vm):
with asyncio_patch("gns3server.compute.qemu.Qemu.binary_list", return_value=ret) as mock:
response = await compute_api.get("/qemu/binaries".format(project_id=vm["project_id"]))
assert mock.called_with(None)
mock.assert_called_with(None)
assert response.status == 200
assert response.json == ret
@ -271,7 +271,7 @@ async def test_qemu_list_binaries_filter(compute_api, vm):
with asyncio_patch("gns3server.compute.qemu.Qemu.binary_list", return_value=ret) as mock:
response = await compute_api.get("/qemu/binaries".format(project_id=vm["project_id"]), body={"archs": ["i386"]})
assert response.status == 200
assert mock.called_with(["i386"])
mock.assert_called_with(["i386"])
assert response.json == ret