def test_get_application_id_multiple_project(loop, iou): vm1_id = str(uuid.uuid4()) vm2_id = str(uuid.uuid4()) vm3_id = str(uuid.uuid4()) project1 = ProjectManager.instance().create_project() project2 = ProjectManager.instance().create_project() loop.run_until_complete(iou.create_vm("PC 1", project1.id, vm1_id)) loop.run_until_complete(iou.create_vm("PC 2", project1.id, vm2_id)) loop.run_until_complete(iou.create_vm("PC 2", project2.id, vm3_id)) assert iou.get_application_id(vm1_id) == 1 assert iou.get_application_id(vm2_id) == 2 assert iou.get_application_id(vm3_id) == 3
def test_write_file(server, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}): project = ProjectManager.instance().create_project() with open(os.path.join(project.path, "hello"), "w+") as f: f.write("world") response = server.post( "/projects/{project_id}/files/hello".format(project_id=project.id), body="universe", raw=True ) assert response.status == 200 with open(os.path.join(project.path, "hello")) as f: content = f.read() assert content == "universe" response = server.post( "/projects/{project_id}/files/test/false".format(project_id=project.id), body="universe", raw=True ) assert response.status == 404 response = server.post( "/projects/{project_id}/files/../hello".format(project_id=project.id), body="universe", raw=True ) assert response.status == 403
def test_get_mac_id_multiple_project(loop, port_manager): # Cleanup the VPCS object VPCS._instance = None vpcs = VPCS.instance() vpcs.port_manager = port_manager vm1_id = str(uuid.uuid4()) vm2_id = str(uuid.uuid4()) vm3_id = str(uuid.uuid4()) project1 = ProjectManager.instance().create_project() project2 = ProjectManager.instance().create_project() loop.run_until_complete(vpcs.create_vm("PC 1", project1.id, vm1_id)) loop.run_until_complete(vpcs.create_vm("PC 2", project1.id, vm2_id)) loop.run_until_complete(vpcs.create_vm("PC 2", project2.id, vm3_id)) assert vpcs.get_mac_id(vm1_id) == 0 assert vpcs.get_mac_id(vm2_id) == 1 assert vpcs.get_mac_id(vm3_id) == 0
def test_get_application_id_multiple_project(loop, port_manager): # Cleanup the IOU object IOU._instance = None iou = IOU.instance() iou.port_manager = port_manager vm1_id = str(uuid.uuid4()) vm2_id = str(uuid.uuid4()) vm3_id = str(uuid.uuid4()) project1 = ProjectManager.instance().create_project() project2 = ProjectManager.instance().create_project() loop.run_until_complete(iou.create_vm("PC 1", project1.id, vm1_id)) loop.run_until_complete(iou.create_vm("PC 2", project1.id, vm2_id)) loop.run_until_complete(iou.create_vm("PC 2", project2.id, vm3_id)) assert iou.get_application_id(vm1_id) == 1 assert iou.get_application_id(vm2_id) == 2 assert iou.get_application_id(vm3_id) == 3
def test_list_projects(server): ProjectManager.instance()._projects = {} query = {"name": "test", "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"} response = server.post("/projects", query) assert response.status == 201 query = {"name": "test", "project_id": "00010203-0405-0607-0809-0a0b0c0d0e0b"} response = server.post("/projects", query) assert response.status == 201 response = server.get("/projects", example=True) assert response.status == 200 print(response.json) assert len(response.json) == 2 assert response.json[0]["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0b" or response.json[1]["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0b"
def test_import(server, tmpdir, loop, project): with zipfile.ZipFile(str(tmpdir / "test.zip"), 'w') as myzip: myzip.writestr("demo", b"hello") project_id = project.id with open(str(tmpdir / "test.zip"), "rb") as f: response = server.post("/projects/{project_id}/import".format(project_id=project_id), body=f.read(), raw=True) assert response.status == 201 project = ProjectManager.instance().get_project(project_id=project_id) with open(os.path.join(project.path, "demo")) as f: content = f.read() assert content == "hello"
def test_get_file(server, tmpdir): with patch("gns3server.config.Config.get_section_config", return_value={"project_directory": str(tmpdir)}): project = ProjectManager.instance().create_project() with open(os.path.join(project.path, "hello"), "w+") as f: f.write("world") response = server.get("/projects/{project_id}/files/hello".format(project_id=project.id), raw=True) assert response.status == 200 assert response.body == b"world" response = server.get("/projects/{project_id}/files/false".format(project_id=project.id), raw=True) assert response.status == 404 response = server.get("/projects/{project_id}/files/../hello".format(project_id=project.id), raw=True) assert response.status == 403
def test_project_not_found(): pm = ProjectManager.instance() with pytest.raises(aiohttp.web.HTTPNotFound): pm.get_project('00010203-0405-0607-0809-000000000000')
def test_create_project(): pm = ProjectManager.instance() project = pm.create_project( project_id='00010203-0405-0607-0809-0a0b0c0d0e0f') assert project == pm.get_project('00010203-0405-0607-0809-0a0b0c0d0e0f')
def test_create_project(): pm = ProjectManager.instance() project = pm.create_project(project_id='00010203-0405-0607-0809-0a0b0c0d0e0f') assert project == pm.get_project('00010203-0405-0607-0809-0a0b0c0d0e0f')
def project(): """A GNS3 lab""" return ProjectManager.instance().create_project(project_id="a1e920ca-338a-4e9f-b363-aa607b09dd80")