add copyright to files in testAPI
[releng.git] / utils / test / result_collection_api / opnfv_testapi / resources / result_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 ResultCreateRequest(object):
14     def __init__(self,
15                  pod_name=None,
16                  project_name=None,
17                  case_name=None,
18                  installer=None,
19                  version=None,
20                  start_date=None,
21                  stop_date=None,
22                  details=None,
23                  build_tag=None,
24                  scenario=None,
25                  criteria=None,
26                  trust_indicator=None):
27         self.pod_name = pod_name
28         self.project_name = project_name
29         self.case_name = case_name
30         self.installer = installer
31         self.version = version
32         self.start_date = start_date
33         self.stop_date = stop_date
34         self.details = details
35         self.build_tag = build_tag
36         self.scenario = scenario
37         self.criteria = criteria
38         self.trust_indicator = trust_indicator
39
40     def format(self):
41         return {
42             "pod_name": self.pod_name,
43             "project_name": self.project_name,
44             "case_name": self.case_name,
45             "installer": self.installer,
46             "version": self.version,
47             "start_date": self.start_date,
48             "stop_date": self.stop_date,
49             "details": self.details,
50             "build_tag": self.build_tag,
51             "scenario": self.scenario,
52             "criteria": self.criteria,
53             "trust_indicator": self.trust_indicator
54         }
55
56
57 @swagger.model()
58 class TestResult(object):
59     """
60         @property trust_indicator: must be int/long/float
61         @ptype trust_indicator: L{float}
62     """
63     def __init__(self, _id=None, case_name=None, project_name=None,
64                  pod_name=None, installer=None, version=None,
65                  start_date=None, stop_date=None, details=None,
66                  build_tag=None, scenario=None, criteria=None,
67                  trust_indicator=None):
68         self._id = _id
69         self.case_name = case_name
70         self.project_name = project_name
71         self.pod_name = pod_name
72         self.installer = installer
73         self.version = version
74         self.start_date = start_date
75         self.stop_date = stop_date
76         self.details = details
77         self.build_tag = build_tag
78         self.scenario = scenario
79         self.criteria = criteria
80         self.trust_indicator = trust_indicator
81
82     @staticmethod
83     def from_dict(a_dict):
84
85         if a_dict is None:
86             return None
87
88         t = TestResult()
89         t._id = a_dict.get('_id')
90         t.case_name = a_dict.get('case_name')
91         t.pod_name = a_dict.get('pod_name')
92         t.project_name = a_dict.get('project_name')
93         t.description = a_dict.get('description')
94         t.start_date = str(a_dict.get('start_date'))
95         t.stop_date = str(a_dict.get('stop_date'))
96         t.details = a_dict.get('details')
97         t.version = a_dict.get('version')
98         t.installer = a_dict.get('installer')
99         t.build_tag = a_dict.get('build_tag')
100         t.scenario = a_dict.get('scenario')
101         t.criteria = a_dict.get('criteria')
102         # 0 < trust indicator < 1
103         # if bad value =>  set this indicator to 0
104         t.trust_indicator = a_dict.get('trust_indicator')
105         if t.trust_indicator is not None:
106             if isinstance(t.trust_indicator, (int, long, float)):
107                 if t.trust_indicator < 0:
108                     t.trust_indicator = 0
109                 elif t.trust_indicator > 1:
110                     t.trust_indicator = 1
111             else:
112                 t.trust_indicator = 0
113         else:
114             t.trust_indicator = 0
115         return t
116
117     def format(self):
118         return {
119             "case_name": self.case_name,
120             "project_name": self.project_name,
121             "pod_name": self.pod_name,
122             "description": self.description,
123             "start_date": str(self.start_date),
124             "stop_date": str(self.stop_date),
125             "version": self.version,
126             "installer": self.installer,
127             "details": self.details,
128             "build_tag": self.build_tag,
129             "scenario": self.scenario,
130             "criteria": self.criteria,
131             "trust_indicator": self.trust_indicator
132         }
133
134     def format_http(self):
135         return {
136             "_id": str(self._id),
137             "case_name": self.case_name,
138             "project_name": self.project_name,
139             "pod_name": self.pod_name,
140             "description": self.description,
141             "start_date": str(self.start_date),
142             "stop_date": str(self.stop_date),
143             "version": self.version,
144             "installer": self.installer,
145             "details": self.details,
146             "build_tag": self.build_tag,
147             "scenario": self.scenario,
148             "criteria": self.criteria,
149             "trust_indicator": self.trust_indicator
150         }
151
152
153 @swagger.model()
154 class TestResults(object):
155     """
156         @property results:
157         @ptype results: C{list} of L{TestResult}
158     """
159     def __init__(self):
160         self.results = list()
161
162     @staticmethod
163     def from_dict(a_dict):
164         if a_dict is None:
165             return None
166
167         res = TestResults()
168         for result in a_dict.get('results'):
169             res.results.append(TestResult.from_dict(result))
170         return res