mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Change URL for projects: /project becomes /projects and project_id is used instead of uuid.
This commit is contained in:
parent
aeb83a7945
commit
d2699f051d
@ -18,15 +18,14 @@
|
||||
from ..web.route import Route
|
||||
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA
|
||||
from ..modules.project_manager import ProjectManager
|
||||
from aiohttp.web import HTTPConflict
|
||||
|
||||
|
||||
class ProjectHandler:
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/project",
|
||||
description="Create a project on the server",
|
||||
r"/projects",
|
||||
description="Create a new project on the server",
|
||||
output=PROJECT_OBJECT_SCHEMA,
|
||||
input=PROJECT_CREATE_SCHEMA)
|
||||
def create_project(request, response):
|
||||
@ -34,99 +33,99 @@ class ProjectHandler:
|
||||
pm = ProjectManager.instance()
|
||||
p = pm.create_project(
|
||||
location=request.json.get("location"),
|
||||
uuid=request.json.get("uuid"),
|
||||
uuid=request.json.get("project_id"),
|
||||
temporary=request.json.get("temporary", False)
|
||||
)
|
||||
response.json(p)
|
||||
|
||||
@classmethod
|
||||
@Route.get(
|
||||
r"/project/{uuid}",
|
||||
r"/projects/{project_id}",
|
||||
description="Get project information",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
"project_id": "The UUID of the project",
|
||||
},
|
||||
status_codes={
|
||||
200: "OK",
|
||||
404: "Project instance doesn't exist"
|
||||
200: "Success",
|
||||
404: "The project doesn't exist"
|
||||
},
|
||||
output=PROJECT_OBJECT_SCHEMA)
|
||||
def show(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
response.json(project)
|
||||
|
||||
@classmethod
|
||||
@Route.put(
|
||||
r"/project/{uuid}",
|
||||
r"/projects/{project_id}",
|
||||
description="Update a project",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
"project_id": "The UUID of the project",
|
||||
},
|
||||
status_codes={
|
||||
200: "Project updated",
|
||||
404: "Project instance doesn't exist"
|
||||
200: "The project has been updated",
|
||||
404: "The project doesn't exist"
|
||||
},
|
||||
output=PROJECT_OBJECT_SCHEMA,
|
||||
input=PROJECT_UPDATE_SCHEMA)
|
||||
def update(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
project.temporary = request.json.get("temporary", project.temporary)
|
||||
response.json(project)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/project/{uuid}/commit",
|
||||
r"/projects/{project_id}/commit",
|
||||
description="Write changes on disk",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
"project_id": "The UUID of the project",
|
||||
},
|
||||
status_codes={
|
||||
204: "Changes write on disk",
|
||||
404: "Project instance doesn't exist"
|
||||
204: "Changes have been written on disk",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
def commit(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
yield from project.commit()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.post(
|
||||
r"/project/{uuid}/close",
|
||||
description="Close project",
|
||||
r"/projects/{project_id}/close",
|
||||
description="Close a project",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
"project_id": "The UUID of the project",
|
||||
},
|
||||
status_codes={
|
||||
204: "Project closed",
|
||||
404: "Project instance doesn't exist"
|
||||
204: "The project has been closed",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
def close(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
yield from project.close()
|
||||
response.set_status(204)
|
||||
|
||||
@classmethod
|
||||
@Route.delete(
|
||||
r"/project/{uuid}",
|
||||
r"/projects/{project_id}",
|
||||
description="Delete a project from disk",
|
||||
parameters={
|
||||
"uuid": "Project instance UUID",
|
||||
"project_id": "The UUID of the project",
|
||||
},
|
||||
status_codes={
|
||||
204: "Changes write on disk",
|
||||
404: "Project instance doesn't exist"
|
||||
204: "Changes have been written on disk",
|
||||
404: "The project doesn't exist"
|
||||
})
|
||||
def delete(request, response):
|
||||
|
||||
pm = ProjectManager.instance()
|
||||
project = pm.get_project(request.match_info["uuid"])
|
||||
project = pm.get_project(request.match_info["project_id"])
|
||||
yield from project.delete()
|
||||
response.set_status(204)
|
||||
|
@ -152,7 +152,7 @@ class Project:
|
||||
def __json__(self):
|
||||
|
||||
return {
|
||||
"uuid": self._uuid,
|
||||
"project_id": self._uuid,
|
||||
"location": self._location,
|
||||
"temporary": self._temporary
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ PROJECT_CREATE_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"uuid": {
|
||||
"project_id": {
|
||||
"description": "Project UUID",
|
||||
"type": ["string", "null"],
|
||||
"minLength": 36,
|
||||
@ -64,7 +64,7 @@ PROJECT_OBJECT_SCHEMA = {
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"uuid": {
|
||||
"project_id": {
|
||||
"description": "Project UUID",
|
||||
"type": "string",
|
||||
"minLength": 36,
|
||||
@ -77,5 +77,5 @@ PROJECT_OBJECT_SCHEMA = {
|
||||
},
|
||||
},
|
||||
"additionalProperties": False,
|
||||
"required": ["location", "uuid", "temporary"]
|
||||
"required": ["location", "project_id", "temporary"]
|
||||
}
|
||||
|
@ -26,89 +26,89 @@ from tests.utils import asyncio_patch
|
||||
|
||||
def test_create_project_with_dir(server, tmpdir):
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
response = server.post("/project", {"location": str(tmpdir)})
|
||||
response = server.post("/projects", {"location": str(tmpdir)})
|
||||
assert response.status == 200
|
||||
assert response.json["location"] == str(tmpdir)
|
||||
|
||||
|
||||
def test_create_project_without_dir(server):
|
||||
query = {}
|
||||
response = server.post("/project", query)
|
||||
response = server.post("/projects", query)
|
||||
assert response.status == 200
|
||||
assert response.json["uuid"] is not None
|
||||
assert response.json["project_id"] is not None
|
||||
assert response.json["temporary"] is False
|
||||
|
||||
|
||||
def test_create_temporary_project(server):
|
||||
query = {"temporary": True}
|
||||
response = server.post("/project", query)
|
||||
response = server.post("/projects", query)
|
||||
assert response.status == 200
|
||||
assert response.json["uuid"] is not None
|
||||
assert response.json["project_id"] is not None
|
||||
assert response.json["temporary"] is True
|
||||
|
||||
|
||||
def test_create_project_with_uuid(server):
|
||||
query = {"uuid": "00010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||
response = server.post("/project", query)
|
||||
query = {"project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f"}
|
||||
response = server.post("/projects", query)
|
||||
assert response.status == 200
|
||||
assert response.json["uuid"] == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
assert response.json["project_id"] == "00010203-0405-0607-0809-0a0b0c0d0e0f"
|
||||
|
||||
|
||||
def test_show_project(server):
|
||||
query = {"uuid": "00010203-0405-0607-0809-0a0b0c0d0e0f", "location": "/tmp", "temporary": False}
|
||||
query = {"project_id": "00010203-0405-0607-0809-0a0b0c0d0e0f", "location": "/tmp", "temporary": False}
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||
response = server.post("/project", query)
|
||||
response = server.post("/projects", query)
|
||||
assert response.status == 200
|
||||
response = server.get("/project/00010203-0405-0607-0809-0a0b0c0d0e0f", example=True)
|
||||
response = server.get("/projects/00010203-0405-0607-0809-0a0b0c0d0e0f", example=True)
|
||||
assert response.json == query
|
||||
|
||||
|
||||
def test_show_project_invalid_uuid(server):
|
||||
response = server.get("/project/00010203-0405-0607-0809-0a0b0c0d0e42")
|
||||
response = server.get("/projects/00010203-0405-0607-0809-0a0b0c0d0e42")
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_update_temporary_project(server):
|
||||
query = {"temporary": True}
|
||||
response = server.post("/project", query)
|
||||
response = server.post("/projects", query)
|
||||
assert response.status == 200
|
||||
query = {"temporary": False}
|
||||
response = server.put("/project/{uuid}".format(uuid=response.json["uuid"]), query, example=True)
|
||||
response = server.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_commit_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.commit", return_value=True) as mock:
|
||||
response = server.post("/project/{uuid}/commit".format(uuid=project.uuid), example=True)
|
||||
response = server.post("/projects/{project_id}/commit".format(project_id=project.uuid), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_commit_project_invalid_project_uuid(server, project):
|
||||
response = server.post("/project/{uuid}/commit".format(uuid=uuid.uuid4()))
|
||||
def test_commit_project_invalid_uuid(server):
|
||||
response = server.post("/projects/{project_id}/commit".format(project_id=uuid.uuid4()))
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_delete_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.delete", return_value=True) as mock:
|
||||
response = server.delete("/project/{uuid}".format(uuid=project.uuid), example=True)
|
||||
response = server.delete("/projects/{project_id}".format(project_id=project.uuid), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_delete_project_invalid_uuid(server, project):
|
||||
response = server.delete("/project/{uuid}".format(uuid=uuid.uuid4()))
|
||||
def test_delete_project_invalid_uuid(server):
|
||||
response = server.delete("/projects/{project_id}".format(project_id=uuid.uuid4()))
|
||||
assert response.status == 404
|
||||
|
||||
|
||||
def test_close_project(server, project):
|
||||
with asyncio_patch("gns3server.modules.project.Project.close", return_value=True) as mock:
|
||||
response = server.post("/project/{uuid}/close".format(uuid=project.uuid), example=True)
|
||||
response = server.post("/projects/{project_id}/close".format(project_id=project.uuid), example=True)
|
||||
assert response.status == 204
|
||||
assert mock.called
|
||||
|
||||
|
||||
def test_close_project_invalid_uuid(server, project):
|
||||
response = server.post("/project/{uuid}/close".format(uuid=uuid.uuid4()))
|
||||
response = server.post("/projects/{project_id}/close".format(project_id=uuid.uuid4()))
|
||||
assert response.status == 404
|
||||
|
@ -68,7 +68,7 @@ def test_changing_location_not_allowed(tmpdir):
|
||||
|
||||
def test_json(tmpdir):
|
||||
p = Project()
|
||||
assert p.__json__() == {"location": p.location, "uuid": p.uuid, "temporary": False}
|
||||
assert p.__json__() == {"location": p.location, "project_id": p.uuid, "temporary": False}
|
||||
|
||||
|
||||
def test_vm_working_directory(tmpdir, vm):
|
||||
|
Loading…
Reference in New Issue
Block a user