From af7fbe6bb48a84f34742bdf9fc195af7c0924eed Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 27 Nov 2024 15:18:49 +1000 Subject: [PATCH] Fix tests --- tests/compute/test_manager.py | 16 ++++++++-------- tests/handlers/api/compute/test_dynamips.py | 4 ++-- tests/handlers/api/compute/test_qemu.py | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/compute/test_manager.py b/tests/compute/test_manager.py index 556072db..cd9f094b 100644 --- a/tests/compute/test_manager.py +++ b/tests/compute/test_manager.py @@ -239,12 +239,12 @@ async def test_list_images(qemu, tmpdir): os.makedirs(tmp_images_dir, exist_ok=True) for image in fake_images: with open(os.path.join(tmp_images_dir, image), "w+") as f: - f.write("1") + f.write("1234567") with patch("gns3server.utils.images.default_images_directory", return_value=str(tmp_images_dir)): assert sorted(await qemu.list_images(), key=lambda k: k['filename']) == [ - {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1}, - {"filename": "b.qcow2", "path": "b.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1} + {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7}, + {"filename": "b.qcow2", "path": "b.qcow2", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7} ] @@ -255,19 +255,19 @@ async def test_list_images_recursives(qemu, tmpdir): fake_images = ["a.qcow2", "b.qcow2", ".blu.qcow2", "a.qcow2.md5sum"] for image in fake_images: with open(os.path.join(tmp_images_dir, image), "w+") as f: - f.write("1") + f.write("1234567") os.makedirs(os.path.join(tmp_images_dir, "c")) fake_images = ["c.qcow2", "c.qcow2.md5sum"] for image in fake_images: with open(os.path.join(tmp_images_dir, "c", image), "w+") as f: - f.write("1") + f.write("1234567") with patch("gns3server.utils.images.default_images_directory", return_value=str(tmp_images_dir)): assert sorted(await qemu.list_images(), key=lambda k: k['filename']) == [ - {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1}, - {"filename": "b.qcow2", "path": "b.qcow2", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1}, - {"filename": "c.qcow2", "path": force_unix_path(os.path.sep.join(["c", "c.qcow2"])), "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1} + {"filename": "a.qcow2", "path": "a.qcow2", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7}, + {"filename": "b.qcow2", "path": "b.qcow2", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7}, + {"filename": "c.qcow2", "path": force_unix_path(os.path.sep.join(["c", "c.qcow2"])), "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7} ] diff --git a/tests/handlers/api/compute/test_dynamips.py b/tests/handlers/api/compute/test_dynamips.py index 1e0871d3..2831b6e7 100644 --- a/tests/handlers/api/compute/test_dynamips.py +++ b/tests/handlers/api/compute/test_dynamips.py @@ -144,7 +144,7 @@ def fake_image(tmpdir): path = str(tmpdir / "7200.bin") with open(path, "wb+") as f: - f.write(b'\x7fELF\x01\x01\x01') + f.write(b'\x7fELF\x01\x02\x01') os.chmod(path, stat.S_IREAD) return path @@ -168,7 +168,7 @@ async def test_images(compute_api, tmpdir, fake_image, fake_file): assert response.json == [{"filename": "7200.bin", "path": "7200.bin", "filesize": 7, - "md5sum": "e573e8f5c93c6c00783f20c7a170aa6c" + "md5sum": "b0d5aa897d937aced5a6b1046e8f7e2e" }] diff --git a/tests/handlers/api/compute/test_qemu.py b/tests/handlers/api/compute/test_qemu.py index 752ff9a0..08861af6 100644 --- a/tests/handlers/api/compute/test_qemu.py +++ b/tests/handlers/api/compute/test_qemu.py @@ -45,7 +45,7 @@ def fake_qemu_vm(images_dir): img_dir = os.path.join(images_dir, "QEMU") bin_path = os.path.join(img_dir, "linux载.img") with open(bin_path, "w+") as f: - f.write("1") + f.write("1234567") os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) return bin_path @@ -101,7 +101,7 @@ async def test_qemu_create_with_params(compute_api, compute_project, base_params assert response.json["project_id"] == compute_project.id assert response.json["ram"] == 1024 assert response.json["hda_disk_image"] == "linux载.img" - assert response.json["hda_disk_image_md5sum"] == "c4ca4238a0b923820dcc509a6f75849b" + assert response.json["hda_disk_image_md5sum"] == "fcea920f7412b5da7be0cf42b8c93759" @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") @@ -279,7 +279,7 @@ async def test_images(compute_api, fake_qemu_vm): response = await compute_api.get("/qemu/images") assert response.status == 200 - assert {"filename": "linux载.img", "path": "linux载.img", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1} in response.json + assert {"filename": "linux载.img", "path": "linux载.img", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7} in response.json @pytest.mark.skipif(sys.platform.startswith("win"), reason="Does not work on Windows")