add copyright to files in testAPI
[releng.git] / utils / test / result_collection_api / opnfv_testapi / resources / testcase_models.py
1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from opnfv_testapi.tornado_swagger import swagger
10
11
12 @swagger.model()
13 class TestcaseCreateRequest(object):
14     def __init__(self, name, url=None, description=None):
15         self.name = name
16         self.url = url
17         self.description = description
18
19     def format(self):
20         return {
21             "name": self.name,
22             "description": self.description,
23             "url": self.url,
24         }
25
26
27 @swagger.model()
28 class TestcaseUpdateRequest(object):
29     def __init__(self, name=None, description=None, project_name=None):
30         self.name = name
31         self.description = description
32         self.project_name = project_name
33
34     def format(self):
35         return {
36             "name": self.name,
37             "description": self.description,
38             "project_name": self.project_name,
39         }
40
41
42 @swagger.model()
43 class Testcase(object):
44     def __init__(self):
45         self._id = None
46         self.name = None
47         self.project_name = None
48         self.description = None
49         self.url = None
50         self.creation_date = None
51
52     @staticmethod
53     def from_dict(a_dict):
54
55         if a_dict is None:
56             return None
57
58         t = Testcase()
59         t._id = a_dict.get('_id')
60         t.project_name = a_dict.get('project_name')
61         t.creation_date = a_dict.get('creation_date')
62         t.name = a_dict.get('name')
63         t.description = a_dict.get('description')
64         t.url = a_dict.get('url')
65
66         return t
67
68     def format(self):
69         return {
70             "name": self.name,
71             "description": self.description,
72             "project_name": self.project_name,
73             "creation_date": str(self.creation_date),
74             "url": self.url
75         }
76
77     def format_http(self):
78         return {
79             "_id": str(self._id),
80             "name": self.name,
81             "project_name": self.project_name,
82             "description": self.description,
83             "creation_date": str(self.creation_date),
84             "url": self.url,
85         }
86
87
88 @swagger.model()
89 class Testcases(object):
90     """
91         @property testcases:
92         @ptype testcases: C{list} of L{Testcase}
93     """
94     def __init__(self):
95         self.testcases = list()
96
97     @staticmethod
98     def from_dict(res_dict):
99         if res_dict is None:
100             return None
101
102         res = Testcases()
103         for testcase in res_dict.get('testcases'):
104             res.testcases.append(Testcase.from_dict(testcase))
105         return res