bb4cb0cf1289db6960444833d8599d77cda9e734
[releng.git] / utils / test / result_collection_api / resources / 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
10
11 class Pod:
12     """ describes a POD platform """
13     def __init__(self):
14         self._id = ""
15         self.name = ""
16         self.creation_date = ""
17
18     @staticmethod
19     def pod_from_dict(pod_dict):
20         if pod_dict is None:
21             return None
22
23         p = Pod()
24         p._id = pod_dict.get('_id')
25         p.creation_date = pod_dict.get('creation_date')
26         p.name = pod_dict.get('name')
27         return p
28
29     def format(self):
30         return {
31             "_id": self._id,
32             "name": self.name,
33             "creation_date": str(self.creation_date),
34         }
35
36
37 class TestProject:
38     """ Describes a test project"""
39
40     def __init__(self):
41         self._id = None
42         self.name = None
43         self.description = None
44         self.creation_date = None
45
46     @staticmethod
47     def testproject_from_dict(testproject_dict):
48
49         if testproject_dict is None:
50             return None
51
52         t = TestProject()
53         t._id = testproject_dict.get('_id')
54         t.creation_date = testproject_dict.get('creation_date')
55         t.name = testproject_dict.get('name')
56         t.description = testproject_dict.get('description')
57
58         return t
59
60     def format(self):
61         return {
62             "name": self.name,
63             "description": self.description,
64             "creation_date": str(self.creation_date)
65         }
66
67     def format_http(self, test_cases=0):
68         return {
69             "_id": str(self._id),
70             "name": self.name,
71             "description": self.description,
72             "creation_date": str(self.creation_date),
73             "test_cases": test_cases
74         }
75
76
77 class TestCase:
78     """ Describes a test case"""
79
80     def __init__(self):
81         self._id = None
82         self.name = None
83         self.project_name = None
84         self.description = None
85         self.creation_date = None
86
87     @staticmethod
88     def test_case_from_dict(testcase_dict):
89
90         if testcase_dict is None:
91             return None
92
93         t = TestCase()
94         t._id = testcase_dict.get('_id')
95         t.project_name = testcase_dict.get('project_name')
96         t.creation_date = testcase_dict.get('creation_date')
97         t.name = testcase_dict.get('name')
98         t.description = testcase_dict.get('description')
99
100         return t
101
102     def format(self):
103         return {
104             "name": self.name,
105             "description": self.description,
106             "project_name": self.project_name,
107             "creation_date": str(self.creation_date)
108         }
109
110     def format_http(self, test_project=None):
111         res = {
112             "_id": str(self._id),
113             "name": self.name,
114             "description": self.description,
115             "creation_date": str(self.creation_date),
116         }
117         if not (test_project is None):
118             res["test_project"] = test_project
119
120         return res
121
122
123 class TestResult:
124     """ Describes a test result"""
125
126     def __init__(self):
127         self._id = None
128         self.case_name = None
129         self.project_name = None
130         self.pod_id = None
131         self.description = None
132         self.creation_date = None
133         self.details = None
134
135     @staticmethod
136     def test_result_from_dict(test_result_dict):
137
138         if test_result_dict is None:
139             return None
140
141         t = TestResult()
142         t._id = test_result_dict.get('_id')
143         t.case_name = test_result_dict.get('case_name')
144         t.project_name = test_result_dict.get('project_name')
145         t.pod_id = test_result_dict.get('pod_id')
146         t.description = test_result_dict.get('description')
147         t.creation_date = str(test_result_dict.get('creation_date'))
148         t.details = test_result_dict.get('details')
149
150         return t
151
152     def format(self):
153         return {
154             "case_name": self.case_name,
155             "project_name": self.project_name,
156             "pod_id": self.pod_id,
157             "description": self.description,
158             "creation_date": self.creation_date,
159             "details": self.details,
160         }
161
162     def format_http(self):
163         return {
164             "_id": str(self._id),
165             "case_name": self.case_name,
166             "project_name": self.project_name,
167             "pod_id": self.pod_id,
168             "description": self.description,
169             "creation_date": self.creation_date,
170             "details": self.details,
171         }