mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Drop code for temporary projects
Fix https://github.com/GNS3/gns3-gui/issues/982
This commit is contained in:
12 files changed
+25
-224
No files matched your search
@@ -76,7 +76,6 @@ def test_path(tmpdir):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.path == os.path.join(directory, p.id)
|
||||
assert os.path.exists(os.path.join(directory, p.id))
|
||||
assert not os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
|
||||
|
||||
def test_init_path(tmpdir):
|
||||
@@ -86,31 +85,6 @@ def test_init_path(tmpdir):
|
||||
assert p.path == str(tmpdir)
|
||||
|
||||
|
||||
def test_changing_path_temporary_flag(tmpdir):
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
p = Project(temporary=True, project_id=str(uuid4()))
|
||||
assert os.path.exists(p.path)
|
||||
original_path = p.path
|
||||
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
|
||||
p.path = str(tmpdir)
|
||||
|
||||
|
||||
def test_temporary_path():
|
||||
p = Project(temporary=True, project_id=str(uuid4()))
|
||||
assert os.path.exists(p.path)
|
||||
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
|
||||
|
||||
def test_remove_temporary_flag():
|
||||
p = Project(temporary=True, project_id=str(uuid4()))
|
||||
assert os.path.exists(p.path)
|
||||
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
p.temporary = False
|
||||
assert not os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||
|
||||
|
||||
def test_changing_path_not_allowed(tmpdir):
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=False):
|
||||
with pytest.raises(aiohttp.web.HTTPForbidden):
|
||||
@@ -120,7 +94,7 @@ def test_changing_path_not_allowed(tmpdir):
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project(project_id=str(uuid4()))
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "temporary": False}
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id}
|
||||
|
||||
|
||||
def test_node_working_directory(tmpdir, node):
|
||||
@@ -201,40 +175,6 @@ def test_project_close(loop, node, project):
|
||||
assert node.id not in node.manager._nodes
|
||||
|
||||
|
||||
def test_project_close_temporary_project(loop, manager):
|
||||
"""A temporary project is deleted when closed"""
|
||||
|
||||
project = Project(temporary=True, project_id=str(uuid4()))
|
||||
directory = project.path
|
||||
assert os.path.exists(directory)
|
||||
loop.run_until_complete(asyncio.async(project.close()))
|
||||
assert os.path.exists(directory) is False
|
||||
|
||||
def test_clean_project_directory(tmpdir):
|
||||
|
||||
# A non anonymous project with uuid.
|
||||
project1 = tmpdir / uuid4()
|
||||
project1.mkdir()
|
||||
|
||||
# A non anonymous project.
|
||||
oldproject = tmpdir / uuid4()
|
||||
oldproject.mkdir()
|
||||
|
||||
# an anonymous project
|
||||
project2 = tmpdir / uuid4()
|
||||
project2.mkdir()
|
||||
tmp = (project2 / ".gns3_temporary")
|
||||
with open(str(tmp), 'w+') as f:
|
||||
f.write("1")
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
Project.clean_project_directory()
|
||||
|
||||
assert os.path.exists(str(project1))
|
||||
assert os.path.exists(str(oldproject))
|
||||
assert not os.path.exists(str(project2))
|
||||
|
||||
|
||||
def test_list_files(tmpdir, loop):
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"projects_path": str(tmpdir)}):
|
||||
|
||||
@@ -27,9 +27,10 @@ from uuid import uuid4
|
||||
from gns3server.controller.project import Project
|
||||
from gns3server.config import Config
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project(controller):
|
||||
return Project(controller=controller)
|
||||
return Project(controller=controller)
|
||||
|
||||
|
||||
def test_affect_uuid():
|
||||
@@ -42,7 +43,7 @@ def test_affect_uuid():
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project()
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "temporary": False, "path": p.path}
|
||||
assert p.__json__() == {"name": p.name, "project_id": p.id, "path": p.path}
|
||||
|
||||
|
||||
def test_path(tmpdir):
|
||||
@@ -99,7 +100,6 @@ def test_add_node_local(async_run, controller):
|
||||
compute.post.assert_any_call('/projects', data={
|
||||
"name": project._name,
|
||||
"project_id": project._id,
|
||||
"temporary": project._temporary,
|
||||
"path": project._path
|
||||
})
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
@@ -127,8 +127,7 @@ def test_add_node_non_local(async_run, controller):
|
||||
|
||||
compute.post.assert_any_call('/projects', data={
|
||||
"name": project._name,
|
||||
"project_id": project._id,
|
||||
"temporary": project._temporary
|
||||
"project_id": project._id
|
||||
})
|
||||
compute.post.assert_any_call('/projects/{}/vpcs/nodes'.format(project.id),
|
||||
data={'node_id': node.id,
|
||||
|
||||
@@ -44,16 +44,6 @@ def test_create_project_without_dir(http_compute):
|
||||
response = http_compute.post("/projects", query, example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["project_id"] == "10010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert response.json["temporary"] is False
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
|
||||
def test_create_temporary_project(http_compute):
|
||||
query = {"name": "test", "temporary": True, "project_id": "20010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||
response = http_compute.post("/projects", query)
|
||||
assert response.status == 201
|
||||
assert response.json["project_id"] == "20010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert response.json["temporary"] is True
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
|
||||
@@ -66,13 +56,12 @@ def test_create_project_with_uuid(http_compute):
|
||||
|
||||
|
||||
def test_show_project(http_compute):
|
||||
query = {"name": "test", "project_id": "40010203-0405-0607-0809-0a0b0c0d0e02", "temporary": False}
|
||||
query = {"name": "test", "project_id": "40010203-0405-0607-0809-0a0b0c0d0e02"}
|
||||
response = http_compute.post("/projects", query)
|
||||
assert response.status == 201
|
||||
response = http_compute.get("/projects/40010203-0405-0607-0809-0a0b0c0d0e02", example=True)
|
||||
assert len(response.json.keys()) == 3
|
||||
assert len(response.json.keys()) == 2
|
||||
assert response.json["project_id"] == "40010203-0405-0607-0809-0a0b0c0d0e02"
|
||||
assert response.json["temporary"] is False
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
|
||||
@@ -97,35 +86,7 @@ def test_list_projects(http_compute):
|
||||
assert "51010203-0405-0607-0809-0a0b0c0d0e0f" in [p["project_id"] for p in response.json]
|
||||
|
||||
|
||||
def test_update_temporary_project(http_compute):
|
||||
query = {"name": "test", "temporary": True, "project_id": "60010203-0405-0607-0809-0a0b0c0d0e0b"}
|
||||
response = http_compute.post("/projects", query)
|
||||
assert response.status == 201
|
||||
query = {"name": "test", "temporary": False}
|
||||
response = http_compute.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json["temporary"] is False
|
||||
|
||||
|
||||
def test_update_path_project_temporary(http_compute, tmpdir):
|
||||
|
||||
os.makedirs(str(tmpdir / "a"))
|
||||
os.makedirs(str(tmpdir / "b"))
|
||||
|
||||
with patch("gns3server.compute.project.Project.is_local", return_value=True):
|
||||
response = http_compute.post("/projects", {"name": "first_name", "path": str(tmpdir / "a"), "temporary": True, "project_id": "70010203-0405-0607-0809-0a0b0c0d0e0b"})
|
||||
assert response.status == 201
|
||||
assert response.json["name"] == "first_name"
|
||||
query = {"name": "second_name", "path": str(tmpdir / "b")}
|
||||
response = http_compute.put("/projects/{project_id}".format(project_id=response.json["project_id"]), query, example=True)
|
||||
assert response.status == 200
|
||||
assert response.json["name"] == "second_name"
|
||||
|
||||
assert not os.path.exists(str(tmpdir / "a"))
|
||||
assert os.path.exists(str(tmpdir / "b"))
|
||||
|
||||
|
||||
def test_update_path_project_non_temporary(http_compute, tmpdir):
|
||||
def test_update_path_project(http_compute, tmpdir):
|
||||
|
||||
os.makedirs(str(tmpdir / "a"))
|
||||
os.makedirs(str(tmpdir / "b"))
|
||||
|
||||
@@ -54,16 +54,14 @@ def test_create_project_without_dir(http_controller):
|
||||
response = http_controller.post("/projects", query, example=True)
|
||||
assert response.status == 201
|
||||
assert response.json["project_id"] == "10010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert response.json["temporary"] is False
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
|
||||
def test_create_temporary_project(http_controller):
|
||||
query = {"name": "test", "temporary": True, "project_id": "20010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||
query = {"name": "test", "project_id": "20010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||
response = http_controller.post("/projects", query)
|
||||
assert response.status == 201
|
||||
assert response.json["project_id"] == "20010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert response.json["temporary"] is True
|
||||
assert response.json["name"] == "test"
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user