1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00

Fix tests checking the local flag

This commit is contained in:
Julien Duponchelle 2016-11-04 15:42:29 +01:00
parent ea94731418
commit 74695efe90
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 71 additions and 68 deletions

View File

@ -206,10 +206,10 @@ def test_close(vm, port_manager, loop):
assert vm.is_running() is False
def test_path(vm, fake_iou_bin):
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
vm.path = fake_iou_bin
assert vm.path == fake_iou_bin
def test_path(vm, fake_iou_bin, config):
config.set_section_config("Server", {"local": True})
vm.path = fake_iou_bin
assert vm.path == fake_iou_bin
def test_path_relative(vm, fake_iou_bin, tmpdir):
@ -218,17 +218,17 @@ def test_path_relative(vm, fake_iou_bin, tmpdir):
assert vm.path == fake_iou_bin
def test_path_invalid_bin(vm, tmpdir):
def test_path_invalid_bin(vm, tmpdir, config):
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
path = str(tmpdir / "test.bin")
config.set_section_config("Server", {"local": True})
path = str(tmpdir / "test.bin")
with open(path, "w+") as f:
f.write("BUG")
with open(path, "w+") as f:
f.write("BUG")
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
def test_create_netmap_config(vm):

View File

@ -88,7 +88,7 @@ def test_create_node_old_topology(loop, project, tmpdir, vpcs):
assert f.read() == "1"
def test_get_abs_image_path(qemu, tmpdir):
def test_get_abs_image_path(qemu, tmpdir, config):
os.makedirs(str(tmpdir / "QEMU"))
path1 = force_unix_path(str(tmpdir / "test1.bin"))
open(path1, 'w+').close()
@ -96,15 +96,15 @@ def test_get_abs_image_path(qemu, tmpdir):
path2 = force_unix_path(str(tmpdir / "QEMU" / "test2.bin"))
open(path2, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert qemu.get_abs_image_path(path1) == path1
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path(path2) == path2
assert qemu.get_abs_image_path("test2.bin") == path2
assert qemu.get_abs_image_path("../test1.bin") == path1
config.set_section_config("Server", {"images_path": str(tmpdir)})
assert qemu.get_abs_image_path(path1) == path1
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path(path2) == path2
assert qemu.get_abs_image_path("test2.bin") == path2
assert qemu.get_abs_image_path("../test1.bin") == path1
def test_get_abs_image_path_non_local(qemu, tmpdir):
def test_get_abs_image_path_non_local(qemu, tmpdir, config):
path1 = tmpdir / "images" / "QEMU" / "test1.bin"
path1.write("1", ensure=True)
path1 = force_unix_path(str(path1))
@ -114,18 +114,18 @@ def test_get_abs_image_path_non_local(qemu, tmpdir):
path2 = force_unix_path(str(path2))
# If non local we can't use path outside images directory
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": False}):
assert qemu.get_abs_image_path(path1) == path1
with pytest.raises(NodeError):
qemu.get_abs_image_path(path2)
with pytest.raises(NodeError):
qemu.get_abs_image_path("C:\\test2.bin")
config.set_section_config("Server", {"images_path": str(tmpdir / "images"), "local": False})
assert qemu.get_abs_image_path(path1) == path1
with pytest.raises(NodeError):
qemu.get_abs_image_path(path2)
with pytest.raises(NodeError):
qemu.get_abs_image_path("C:\\test2.bin")
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": True}):
assert qemu.get_abs_image_path(path2) == path2
config.set_section_config("Server", {"images_path": str(tmpdir / "images"), "local": True})
assert qemu.get_abs_image_path(path2) == path2
def test_get_abs_image_additional_image_paths(qemu, tmpdir):
def test_get_abs_image_additional_image_paths(qemu, tmpdir, config):
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
path1.write("1", ensure=True)
path1 = force_unix_path(str(path1))
@ -134,20 +134,21 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
path2.write("1", ensure=True)
path2 = force_unix_path(str(path2))
with patch("gns3server.config.Config.get_section_config", return_value={
"images_path": str(tmpdir / "images1"),
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
"local": False}):
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path2)) == path2
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
"local": False})
with pytest.raises(ImageMissingError):
qemu.get_abs_image_path("test4.bin")
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path2)) == path2
with pytest.raises(ImageMissingError):
qemu.get_abs_image_path("test4.bin")
def test_get_abs_image_recursive(qemu, tmpdir):
def test_get_abs_image_recursive(qemu, tmpdir, config):
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test1.bin"
path1.write("1", ensure=True)
path1 = force_unix_path(str(path1))
@ -156,16 +157,16 @@ def test_get_abs_image_recursive(qemu, tmpdir):
path2.write("1", ensure=True)
path2 = force_unix_path(str(path2))
with patch("gns3server.config.Config.get_section_config", return_value={
"images_path": str(tmpdir / "images1"),
"local": False}):
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path1)) == path1
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"local": False})
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path1)) == path1
def test_get_abs_image_recursive_ova(qemu, tmpdir):
def test_get_abs_image_recursive_ova(qemu, tmpdir, config):
path1 = tmpdir / "images1" / "QEMU" / "demo" / "test.ova" / "test1.bin"
path1.write("1", ensure=True)
path1 = force_unix_path(str(path1))
@ -174,16 +175,16 @@ def test_get_abs_image_recursive_ova(qemu, tmpdir):
path2.write("1", ensure=True)
path2 = force_unix_path(str(path2))
with patch("gns3server.config.Config.get_section_config", return_value={
"images_path": str(tmpdir / "images1"),
"local": False}):
assert qemu.get_abs_image_path("test.ova/test1.bin") == path1
assert qemu.get_abs_image_path("test.ova/test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path1)) == path1
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"local": False})
assert qemu.get_abs_image_path("test.ova/test1.bin") == path1
assert qemu.get_abs_image_path("test.ova/test2.bin") == path2
# Absolute path
assert qemu.get_abs_image_path(str(path1)) == path1
def test_get_relative_image_path(qemu, tmpdir):
def test_get_relative_image_path(qemu, tmpdir, config):
os.makedirs(str(tmpdir / "images1" / "QEMU"))
path1 = force_unix_path(str(tmpdir / "images1" / "test1.bin"))
open(path1, 'w+').close()
@ -195,26 +196,28 @@ def test_get_relative_image_path(qemu, tmpdir):
path3 = force_unix_path(str(tmpdir / "images2" / "test3.bin"))
open(path3, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"additional_images_path": str(tmpdir / "images2")
}):
assert qemu.get_relative_image_path(path1) == "test1.bin"
assert qemu.get_relative_image_path("test1.bin") == "test1.bin"
assert qemu.get_relative_image_path(path2) == "test2.bin"
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
})
assert qemu.get_relative_image_path(path1) == "test1.bin"
assert qemu.get_relative_image_path("test1.bin") == "test1.bin"
assert qemu.get_relative_image_path(path2) == "test2.bin"
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
def test_get_relative_image_path_ova(qemu, tmpdir):
def test_get_relative_image_path_ova(qemu, tmpdir, config):
os.makedirs(str(tmpdir / "QEMU" / "test.ova"))
path = str(tmpdir / "QEMU" / "test.ova" / "test.bin")
open(path, 'w+').close()
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}):
assert qemu.get_relative_image_path(path) == os.path.join("test.ova", "test.bin")
assert qemu.get_relative_image_path(os.path.join("test.ova", "test.bin")) == os.path.join("test.ova", "test.bin")
config.set_section_config("Server", {
"images_path": str(tmpdir)
})
assert qemu.get_relative_image_path(path) == os.path.join("test.ova", "test.bin")
assert qemu.get_relative_image_path(os.path.join("test.ova", "test.bin")) == os.path.join("test.ova", "test.bin")
def test_list_images(loop, qemu, tmpdir):