Handlers: cleanup and fixes.

This commit is contained in:
grossmj committed 2016-05-13 18:00:07 -06:00
1 parent 885d93be02
commit f81d35cc29
33 files changed
+723 -766

No files matched your search

+9 -2
View File
@@ -96,9 +96,16 @@ def test_docker_delete(http_compute, vm):
assert response.status == 204
def test_docker_reload(http_compute, vm):
def test_docker_pause(http_compute, vm):
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.pause", return_value=True) as mock:
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/suspend".format(project_id=vm["project_id"], node_id=vm["node_id"]))
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/pause".format(project_id=vm["project_id"], node_id=vm["node_id"]))
assert mock.called
assert response.status == 204
def test_docker_unpause(http_compute, vm):
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.unpause", return_value=True) as mock:
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/unpause".format(project_id=vm["project_id"], node_id=vm["node_id"]))
assert mock.called
assert response.status == 204
+6 -6
View File
@@ -151,17 +151,17 @@ def fake_file(tmpdir):
return path
def test_vms(http_compute, tmpdir, fake_dynamips, fake_file):
def test_images(http_compute, tmpdir, fake_dynamips, fake_file):
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir), example=True):
response = http_compute.get("/dynamips/nodes")
response = http_compute.get("/dynamips/images")
assert response.status == 200
assert response.json == [{"filename": "7200.bin", "path": "7200.bin"}]
def test_upload_vm(http_compute, tmpdir):
def test_upload_image(http_compute, tmpdir):
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/dynamips/nodes/test2", body="TEST", raw=True)
response = http_compute.post("/dynamips/images/test2", body="TEST", raw=True)
assert response.status == 204
with open(str(tmpdir / "test2")) as f:
@@ -172,11 +172,11 @@ def test_upload_vm(http_compute, tmpdir):
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
def test_upload_vm_permission_denied(http_compute, tmpdir):
def test_upload_image_permission_denied(http_compute, tmpdir):
with open(str(tmpdir / "test2.tmp"), "w+") as f:
f.write("")
os.chmod(str(tmpdir / "test2.tmp"), 0)
with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/dynamips/nodes/test2", body="TEST", raw=True)
response = http_compute.post("/dynamips/images/test2", body="TEST", raw=True)
assert response.status == 409
+4 -4
View File
@@ -328,17 +328,17 @@ def test_get_configs_with_startup_config_file(http_compute, project, vm):
assert response.json["startup_config_content"] == "TEST"
def test_vms(http_compute, tmpdir, fake_iou_bin):
def test_images(http_compute, tmpdir, fake_iou_bin):
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir)):
response = http_compute.get("/iou/nodes", example=True)
response = http_compute.get("/iou/images", example=True)
assert response.status == 200
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
def test_upload_vm(http_compute, tmpdir):
def test_image_vm(http_compute, tmpdir):
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/iou/nodes/test2", body="TEST", raw=True)
response = http_compute.post("/iou/images/test2", body="TEST", raw=True)
assert response.status == 204
with open(str(tmpdir / "test2")) as f:
+10 -10
View File
@@ -224,16 +224,16 @@ def test_qemu_list_binaries_filter(http_compute, vm):
assert response.json == ret
def test_vms(http_compute, tmpdir, fake_qemu_vm):
def test_images(http_compute, tmpdir, fake_qemu_vm):
response = http_compute.get("/qemu/nodes")
response = http_compute.get("/qemu/images")
assert response.status == 200
assert response.json == [{"filename": "linux载.img", "path": "linux载.img"}]
def test_upload_vm(http_compute, tmpdir):
def test_upload_image(http_compute, tmpdir):
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/qemu/nodes/test2", body="TEST", raw=True)
response = http_compute.post("/qemu/images/test2", body="TEST", raw=True)
assert response.status == 204
with open(str(tmpdir / "test2")) as f:
@@ -244,9 +244,9 @@ def test_upload_vm(http_compute, tmpdir):
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
def test_upload_vm_ova(http_compute, tmpdir):
def test_upload_image_ova(http_compute, tmpdir):
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/qemu/nodes/test2.ova/test2.vmdk", body="TEST", raw=True)
response = http_compute.post("/qemu/images/test2.ova/test2.vmdk", body="TEST", raw=True)
assert response.status == 204
with open(str(tmpdir / "test2.ova" / "test2.vmdk")) as f:
@@ -257,19 +257,19 @@ def test_upload_vm_ova(http_compute, tmpdir):
assert checksum == "033bd94b1168d7e4f0d644c3c95e35bf"
def test_upload_vm_forbiden_location(http_compute, tmpdir):
def test_upload_image_forbiden_location(http_compute, tmpdir):
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/qemu/nodes/../../test2", body="TEST", raw=True)
response = http_compute.post("/qemu/images/../../test2", body="TEST", raw=True)
assert response.status == 403
def test_upload_vm_permission_denied(http_compute, tmpdir):
def test_upload_image_permission_denied(http_compute, tmpdir):
with open(str(tmpdir / "test2.tmp"), "w+") as f:
f.write("")
os.chmod(str(tmpdir / "test2.tmp"), 0)
with patch("gns3server.compute.Qemu.get_images_directory", return_value=str(tmpdir),):
response = http_compute.post("/qemu/nodes/test2", body="TEST", raw=True)
response = http_compute.post("/qemu/images/test2", body="TEST", raw=True)
assert response.status == 409
+1 -1
View File
@@ -45,7 +45,7 @@ def compute(http_controller, async_run):
@pytest.fixture
def project(http_controller, async_run):
return async_run(Controller.instance().addProject())
return async_run(Controller.instance().add_project())
def test_create_link(http_controller, tmpdir, project, compute, async_run):
+7 -12
View File
@@ -44,7 +44,7 @@ def compute(http_controller, async_run):
@pytest.fixture
def project(http_controller, async_run):
return async_run(Controller.instance().addProject())
return async_run(Controller.instance().add_project())
@pytest.fixture
@@ -103,7 +103,7 @@ def test_update_node(http_controller, tmpdir, project, compute, node):
"startup_script": "echo test"
}
}, example=True)
assert response.status == 201
assert response.status == 200
assert response.json["name"] == "test"
assert "name" not in response.json["properties"]
@@ -113,17 +113,14 @@ def test_start_node(http_controller, tmpdir, project, compute, node):
compute.post = AsyncioMagicMock()
response = http_controller.post("/projects/{}/nodes/{}/start".format(project.id, node.id), example=True)
assert response.status == 201
assert response.json["name"] == node.name
assert response.status == 204
def test_stop_node(http_controller, tmpdir, project, compute, node):
response = MagicMock()
compute.post = AsyncioMagicMock()
response = http_controller.post("/projects/{}/nodes/{}/stop".format(project.id, node.id), example=True)
assert response.status == 201
assert response.json["name"] == node.name
assert response.status == 204
def test_suspend_node(http_controller, tmpdir, project, compute, node):
@@ -131,8 +128,7 @@ def test_suspend_node(http_controller, tmpdir, project, compute, node):
compute.post = AsyncioMagicMock()
response = http_controller.post("/projects/{}/nodes/{}/suspend".format(project.id, node.id), example=True)
assert response.status == 201
assert response.json["name"] == node.name
assert response.status == 204
def test_reload_node(http_controller, tmpdir, project, compute, node):
@@ -140,8 +136,7 @@ def test_reload_node(http_controller, tmpdir, project, compute, node):
compute.post = AsyncioMagicMock()
response = http_controller.post("/projects/{}/nodes/{}/reload".format(project.id, node.id), example=True)
assert response.status == 201
assert response.json["name"] == node.name
assert response.status == 204
def test_delete_node(http_controller, tmpdir, project, compute, node):
@@ -149,4 +144,4 @@ def test_delete_node(http_controller, tmpdir, project, compute, node):
compute.post = AsyncioMagicMock()
response = http_controller.delete("/projects/{}/nodes/{}".format(project.id, node.id), example=True)
assert response.status == 201
assert response.status == 204