1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
##############################################################################
# Copyright (c) 2015 Orange
# guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
from opnfv_testapi.handlers import base_handlers
from opnfv_testapi.models import project_models
from opnfv_testapi.tornado_swagger import swagger
class GenericProjectHandler(base_handlers.GenericApiHandler):
def __init__(self, application, request, **kwargs):
super(GenericProjectHandler, self).__init__(application,
request,
**kwargs)
self.table = 'projects'
self.table_cls = project_models.Project
class ProjectCLHandler(GenericProjectHandler):
@swagger.operation(nickname="listProjects")
def get(self):
"""
@description: Retrieve project(s) on a specific details.
@notes: Retrieve project(s) on a specific details.
Available filters for this request are :
- name : project name
GET /projects?name=functest
@return 200: all projects consist with query,
empty list if no result is found
@param name: project name
@type name: L{string}
@in name: query
@required name: False
"""
self._list()
@swagger.operation(nickname="createProject")
def post(self):
"""
@description: create a project
@param body: project to be created
@type body: L{ProjectCreateRequest}
@in body: body
@rtype: L{CreateResponse}
@return 200: project is created.
@raise 403: project already exists
@raise 400: body or name not provided
"""
def query():
return {'name': self.json_args.get('name')}
miss_fields = ['name']
self._create(miss_fields=miss_fields, query=query)
class ProjectGURHandler(GenericProjectHandler):
@swagger.operation(nickname='getProjectByName')
def get(self, project_name):
"""
@description: get a single project by project_name
@rtype: L{Project}
@return 200: project exist
@raise 404: project not exist
"""
self._get_one(query={'name': project_name})
@swagger.operation(nickname="updateProjectByName")
def put(self, project_name):
"""
@description: update a single project by project_name
@param body: project to be updated
@type body: L{ProjectUpdateRequest}
@in body: body
@rtype: L{Project}
@return 200: update success
@raise 404: project not exist
@raise 403: new project name already exist or nothing to update
"""
query = {'name': project_name}
db_keys = ['name']
self._update(query=query, db_keys=db_keys)
@swagger.operation(nickname='deleteProjectByName')
def delete(self, project_name):
"""
@description: delete a project by project_name
@return 200: delete success
@raise 404: project not exist
"""
self._delete(query={'name': project_name})
|