From b7d43b29cda0ec9aae5c2730ce74e7a07ce5e0e7 Mon Sep 17 00:00:00 2001 From: grossmj Date: Mon, 2 Dec 2024 13:02:08 +1000 Subject: [PATCH] Fix tests after merging --- gns3server/controller/project.py | 6 +----- gns3server/utils/images.py | 1 - tests/api/routes/compute/test_qemu_nodes.py | 7 ++++--- tests/utils/test_images.py | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 2d91069a..6423cdee 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -1339,7 +1339,6 @@ class Project: Copy the project files directly rather than in an import-export fashion. :param name: Name of the new project. A new one will be generated in case of conflicts - :param location: Parent directory of the new project :param reset_mac_addresses: Reset MAC addresses for the new project """ @@ -1352,10 +1351,7 @@ class Project: p_work = pathlib.Path(self.path).parent.absolute() t0 = time.time() new_project_id = str(uuid.uuid4()) - if location: - new_project_path = p_work.joinpath(location) - else: - new_project_path = p_work.joinpath(new_project_id) + new_project_path = p_work.joinpath(new_project_id) # copy dir await wait_run_in_executor(shutil.copytree, self.path, new_project_path.as_posix(), symlinks=True, ignore_dangling_symlinks=True) log.info("Project content copied from '{}' to '{}' in {}s".format(self.path, new_project_path, time.time() - t0)) diff --git a/gns3server/utils/images.py b/gns3server/utils/images.py index f91041ab..d7adf362 100644 --- a/gns3server/utils/images.py +++ b/gns3server/utils/images.py @@ -98,7 +98,6 @@ async def list_images(image_type): else: path = os.path.relpath(os.path.join(root, filename), default_directory) - images.append( { "filename": filename, diff --git a/tests/api/routes/compute/test_qemu_nodes.py b/tests/api/routes/compute/test_qemu_nodes.py index f0d3a44d..61144fe2 100644 --- a/tests/api/routes/compute/test_qemu_nodes.py +++ b/tests/api/routes/compute/test_qemu_nodes.py @@ -48,7 +48,7 @@ def fake_qemu_vm(images_dir) -> str: 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 @@ -127,7 +127,7 @@ async def test_qemu_create_with_params(app: FastAPI, 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.parametrize( @@ -387,7 +387,8 @@ async def test_images(app: FastAPI, compute_client: AsyncClient, fake_qemu_vm) - response = await compute_client.get(app.url_path_for("compute:get_qemu_images")) assert response.status_code == status.HTTP_200_OK - assert {"filename": "linux载.img", "path": "linux载.img", "md5sum": "c4ca4238a0b923820dcc509a6f75849b", "filesize": 1} in response.json() + print(response.json()) + assert {"filename": "linux载.img", "path": "linux载.img", "md5sum": "fcea920f7412b5da7be0cf42b8c93759", "filesize": 7} in response.json() async def test_upload_image(app: FastAPI, compute_client: AsyncClient, tmpdir: str) -> None: diff --git a/tests/utils/test_images.py b/tests/utils/test_images.py index 21bbbd9a..53b2acf0 100644 --- a/tests/utils/test_images.py +++ b/tests/utils/test_images.py @@ -161,7 +161,7 @@ async def test_list_images(tmpdir, config): config.settings.Server.images_path = str(tmpdir / "images1") config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2") - assert list_images("dynamips") == [ + assert await list_images("dynamips") == [ { 'filename': 'ios_image_1.image', 'filesize': 7, @@ -177,7 +177,7 @@ async def test_list_images(tmpdir, config): ] if sys.platform.startswith("linux"): - assert list_images("iou") == [ + assert await list_images("iou") == [ { 'filename': 'iou64.bin', 'filesize': 7, @@ -192,7 +192,7 @@ async def test_list_images(tmpdir, config): } ] - assert list_images("qemu") == [ + assert await list_images("qemu") == [ { 'filename': 'qemu_image.qcow2', 'filesize': 7,