1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18: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,8 +206,8 @@ 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}):
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
@ -218,9 +218,9 @@ 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}):
config.set_section_config("Server", {"local": True})
path = str(tmpdir / "test.bin")
with open(path, "w+") as f:

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,7 +96,7 @@ 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)}):
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
@ -104,7 +104,7 @@ def test_get_abs_image_path(qemu, tmpdir):
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}):
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}):
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,10 +134,11 @@ 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={
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
"local": False}):
"local": False})
assert qemu.get_abs_image_path("test1.bin") == path1
assert qemu.get_abs_image_path("test2.bin") == path2
# Absolute path
@ -147,7 +148,7 @@ def test_get_abs_image_additional_image_paths(qemu, tmpdir):
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={
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"local": False}):
"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={
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"local": False}):
"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,10 +196,10 @@ 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"
@ -207,12 +208,14 @@ def test_get_relative_image_path(qemu, tmpdir):
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)}):
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")