1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Add test for unicode char in images path

Ref #401
This commit is contained in:
Julien Duponchelle 2016-01-26 15:32:40 +01:00
parent ee2104ba35
commit 119a2a3b66
4 changed files with 16 additions and 12 deletions

View File

@ -1500,7 +1500,6 @@ class QemuVM(BaseVM):
answer[field] = getattr(self, field) answer[field] = getattr(self, field)
except AttributeError: except AttributeError:
pass pass
answer["hda_disk_image"] = self.manager.get_relative_image_path(self._hda_disk_image) answer["hda_disk_image"] = self.manager.get_relative_image_path(self._hda_disk_image)
answer["hda_disk_image_md5sum"] = md5sum(self._hda_disk_image) answer["hda_disk_image_md5sum"] = md5sum(self._hda_disk_image)
answer["hdb_disk_image"] = self.manager.get_relative_image_path(self._hdb_disk_image) answer["hdb_disk_image"] = self.manager.get_relative_image_path(self._hdb_disk_image)

View File

@ -147,7 +147,9 @@ def run_around_tests(monkeypatch, port_manager):
port_manager._instance = port_manager port_manager._instance = port_manager
config = Config.instance() config = Config.instance()
config.clear() config.clear()
config.set("Server", "project_directory", tmppath) os.makedirs(os.path.join(tmppath, 'projects'))
config.set("Server", "project_directory", os.path.join(tmppath, 'projects'))
config.set("Server", "images_path", os.path.join(tmppath, 'images'))
config.set("Server", "auth", False) config.set("Server", "auth", False)
# Prevent executions of the VM if we forgot to mock something # Prevent executions of the VM if we forgot to mock something
@ -158,7 +160,7 @@ def run_around_tests(monkeypatch, port_manager):
# Force turn off KVM because it's not available on CI # Force turn off KVM because it's not available on CI
config.set("Qemu", "enable_kvm", False) config.set("Qemu", "enable_kvm", False)
monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: tmppath) monkeypatch.setattr("gns3server.modules.project.Project._get_default_project_directory", lambda *args: os.path.join(tmppath, 'projects'))
# Force sys.platform to the original value. Because it seem not be restore correctly at each tests # Force sys.platform to the original value. Because it seem not be restore correctly at each tests
sys.platform = sys.original_platform sys.platform = sys.original_platform

View File

@ -23,7 +23,6 @@ from tests.utils import asyncio_patch
from unittest.mock import patch from unittest.mock import patch
from gns3server.config import Config from gns3server.config import Config
@pytest.fixture @pytest.fixture
def fake_qemu_bin(): def fake_qemu_bin():
@ -40,7 +39,10 @@ def fake_qemu_bin():
@pytest.fixture @pytest.fixture
def fake_qemu_vm(tmpdir): def fake_qemu_vm(tmpdir):
bin_path = os.path.join(str(tmpdir / "linux.img")) img_dir = Config.instance().get_section_config("Server").get("images_path")
img_dir = os.path.join(img_dir, "QEMU")
os.makedirs(img_dir)
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("1")
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)
@ -86,15 +88,17 @@ def test_qemu_create_platform(server, project, base_params, fake_qemu_bin):
def test_qemu_create_with_params(server, project, base_params, fake_qemu_vm): def test_qemu_create_with_params(server, project, base_params, fake_qemu_vm):
params = base_params params = base_params
params["ram"] = 1024 params["ram"] = 1024
params["hda_disk_image"] = "linux.img" params["hda_disk_image"] = "linux.img"
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), params, example=True) response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), params, example=True)
assert response.status == 201 assert response.status == 201
assert response.route == "/projects/{project_id}/qemu/vms" assert response.route == "/projects/{project_id}/qemu/vms"
assert response.json["name"] == "PC TEST 1" assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id assert response.json["project_id"] == 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"
def test_qemu_get(server, project, vm): def test_qemu_get(server, project, vm):
@ -220,10 +224,9 @@ def test_qemu_list_binaries_filter(server, vm):
def test_vms(server, tmpdir, fake_qemu_vm): def test_vms(server, tmpdir, fake_qemu_vm):
with patch("gns3server.modules.Qemu.get_images_directory", return_value=str(tmpdir), example=True):
response = server.get("/qemu/vms") response = server.get("/qemu/vms")
assert response.status == 200 assert response.status == 200
assert response.json == [{"filename": "linux.img", "path": "linux.img"}] assert response.json == [{"filename": "linux.img", "path": "linux.img"}]
def test_upload_vm(server, tmpdir): def test_upload_vm(server, tmpdir):

View File

@ -21,13 +21,13 @@ from gns3server.utils.images import md5sum, remove_checksum
def test_md5sum(tmpdir): def test_md5sum(tmpdir):
fake_img = str(tmpdir / 'hello') fake_img = str(tmpdir / 'hello')
with open(fake_img, 'w+') as f: with open(fake_img, 'w+') as f:
f.write('hello') f.write('hello')
assert md5sum(fake_img) == '5d41402abc4b2a76b9719d911017c592' assert md5sum(fake_img) == '5d41402abc4b2a76b9719d911017c592'
with open(str(tmpdir / 'hello.md5sum')) as f: with open(str(tmpdir / 'hello.md5sum')) as f:
assert f.read() == '5d41402abc4b2a76b9719d911017c592' assert f.read() == '5d41402abc4b2a76b9719d911017c592'