1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-12 19:38:57 +00:00

Update a project

This commit is contained in:
Julien Duponchelle 2015-01-23 16:13:58 +01:00
parent abc885049f
commit 0e76527ce2
4 changed files with 55 additions and 2 deletions

View File

@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ..web.route import Route
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA
from ..schemas.project import PROJECT_OBJECT_SCHEMA, PROJECT_CREATE_SCHEMA, PROJECT_UPDATE_SCHEMA
from ..modules.project_manager import ProjectManager
from aiohttp.web import HTTPConflict
@ -39,6 +39,26 @@ class ProjectHandler:
)
response.json(p)
@classmethod
@Route.put(
r"/project/{uuid}",
description="Update a project",
parameters={
"uuid": "Project instance UUID",
},
status_codes={
200: "Project updated",
404: "Project instance 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.temporary = request.json.get("temporary", project.temporary)
response.json(project)
@classmethod
@Route.post(
r"/project/{uuid}/commit",

View File

@ -76,6 +76,16 @@ class Project:
return self._vms
@property
def temporary(self):
return self._temporary
@temporary.setter
def temporary(self, temporary):
self._temporary = temporary
def vm_working_directory(self, vm):
"""
Return a working directory for a specific VM.

View File

@ -41,9 +41,22 @@ PROJECT_CREATE_SCHEMA = {
"additionalProperties": False,
}
PROJECT_UPDATE_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to update a Project instance",
"type": "object",
"properties": {
"temporary": {
"description": "If project is a temporary project",
"type": "boolean"
},
},
"additionalProperties": False,
}
PROJECT_OBJECT_SCHEMA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Request validation to create a new Project instance",
"description": "Project instance",
"type": "object",
"properties": {
"location": {

View File

@ -60,6 +60,16 @@ def test_create_project_with_uuid(server):
assert response.json["location"] == "/tmp"
def test_update_temporary_project(server):
query = {"temporary": True}
response = server.post("/project", query)
assert response.status == 200
query = {"temporary": False}
response = server.put("/project/{uuid}".format(uuid=response.json["uuid"]), query)
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)