Fix tests after merging

This commit is contained in:
grossmj 2024-12-02 13:02:08 +10:00
parent cbaa563996
commit b7d43b29cd
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD
4 changed files with 8 additions and 12 deletions

View File

@ -1339,7 +1339,6 @@ class Project:
Copy the project files directly rather than in an import-export fashion. 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 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 :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() p_work = pathlib.Path(self.path).parent.absolute()
t0 = time.time() t0 = time.time()
new_project_id = str(uuid.uuid4()) new_project_id = str(uuid.uuid4())
if location: new_project_path = p_work.joinpath(new_project_id)
new_project_path = p_work.joinpath(location)
else:
new_project_path = p_work.joinpath(new_project_id)
# copy dir # copy dir
await wait_run_in_executor(shutil.copytree, self.path, new_project_path.as_posix(), symlinks=True, ignore_dangling_symlinks=True) 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)) log.info("Project content copied from '{}' to '{}' in {}s".format(self.path, new_project_path, time.time() - t0))

View File

@ -98,7 +98,6 @@ async def list_images(image_type):
else: else:
path = os.path.relpath(os.path.join(root, filename), default_directory) path = os.path.relpath(os.path.join(root, filename), default_directory)
images.append( images.append(
{ {
"filename": filename, "filename": filename,

View File

@ -48,7 +48,7 @@ def fake_qemu_vm(images_dir) -> str:
img_dir = os.path.join(images_dir, "QEMU") img_dir = os.path.join(images_dir, "QEMU")
bin_path = os.path.join(img_dir, "linux载.img") bin_path = os.path.join(img_dir, "linux载.img")
with open(bin_path, "w+") as f: 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) os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
return bin_path 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()["project_id"] == compute_project.id
assert response.json()["ram"] == 1024 assert response.json()["ram"] == 1024
assert response.json()["hda_disk_image"] == "linux载.img" 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( @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")) response = await compute_client.get(app.url_path_for("compute:get_qemu_images"))
assert response.status_code == status.HTTP_200_OK 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: async def test_upload_image(app: FastAPI, compute_client: AsyncClient, tmpdir: str) -> None:

View File

@ -161,7 +161,7 @@ async def test_list_images(tmpdir, config):
config.settings.Server.images_path = str(tmpdir / "images1") config.settings.Server.images_path = str(tmpdir / "images1")
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2") 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', 'filename': 'ios_image_1.image',
'filesize': 7, 'filesize': 7,
@ -177,7 +177,7 @@ async def test_list_images(tmpdir, config):
] ]
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
assert list_images("iou") == [ assert await list_images("iou") == [
{ {
'filename': 'iou64.bin', 'filename': 'iou64.bin',
'filesize': 7, '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', 'filename': 'qemu_image.qcow2',
'filesize': 7, 'filesize': 7,