diff options
author | 2015-08-25 19:28:42 +0200 | |
---|---|---|
committer | 2015-08-25 19:29:33 +0200 | |
commit | 737ff5abfe2711cb8c1e36729e41be723a03305b (patch) | |
tree | d460c2a6bee0c05e564faa992f6e52731f483c73 /result_collection_api/resources/models.py |
Update result_collection_api
Fix lines length regarding pep8.
Add new handlers for cases and results and
HTTP methods to projects.
JIRA : RELENG-7
Change-Id: Idc7c0868384d29f28bccc78540edfb02ae1dfbaf
Signed-off-by: grkoffi <koffirodrigue@gmail.com>
Diffstat (limited to 'result_collection_api/resources/models.py')
-rw-r--r-- | result_collection_api/resources/models.py | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/result_collection_api/resources/models.py b/result_collection_api/resources/models.py new file mode 100644 index 0000000..bb4cb0c --- /dev/null +++ b/result_collection_api/resources/models.py @@ -0,0 +1,171 @@ +############################################################################## +# 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 +############################################################################## + + +class Pod: + """ describes a POD platform """ + def __init__(self): + self._id = "" + self.name = "" + self.creation_date = "" + + @staticmethod + def pod_from_dict(pod_dict): + if pod_dict is None: + return None + + p = Pod() + p._id = pod_dict.get('_id') + p.creation_date = pod_dict.get('creation_date') + p.name = pod_dict.get('name') + return p + + def format(self): + return { + "_id": self._id, + "name": self.name, + "creation_date": str(self.creation_date), + } + + +class TestProject: + """ Describes a test project""" + + def __init__(self): + self._id = None + self.name = None + self.description = None + self.creation_date = None + + @staticmethod + def testproject_from_dict(testproject_dict): + + if testproject_dict is None: + return None + + t = TestProject() + t._id = testproject_dict.get('_id') + t.creation_date = testproject_dict.get('creation_date') + t.name = testproject_dict.get('name') + t.description = testproject_dict.get('description') + + return t + + def format(self): + return { + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date) + } + + def format_http(self, test_cases=0): + return { + "_id": str(self._id), + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date), + "test_cases": test_cases + } + + +class TestCase: + """ Describes a test case""" + + def __init__(self): + self._id = None + self.name = None + self.project_name = None + self.description = None + self.creation_date = None + + @staticmethod + def test_case_from_dict(testcase_dict): + + if testcase_dict is None: + return None + + t = TestCase() + t._id = testcase_dict.get('_id') + t.project_name = testcase_dict.get('project_name') + t.creation_date = testcase_dict.get('creation_date') + t.name = testcase_dict.get('name') + t.description = testcase_dict.get('description') + + return t + + def format(self): + return { + "name": self.name, + "description": self.description, + "project_name": self.project_name, + "creation_date": str(self.creation_date) + } + + def format_http(self, test_project=None): + res = { + "_id": str(self._id), + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date), + } + if not (test_project is None): + res["test_project"] = test_project + + return res + + +class TestResult: + """ Describes a test result""" + + def __init__(self): + self._id = None + self.case_name = None + self.project_name = None + self.pod_id = None + self.description = None + self.creation_date = None + self.details = None + + @staticmethod + def test_result_from_dict(test_result_dict): + + if test_result_dict is None: + return None + + t = TestResult() + t._id = test_result_dict.get('_id') + t.case_name = test_result_dict.get('case_name') + t.project_name = test_result_dict.get('project_name') + t.pod_id = test_result_dict.get('pod_id') + t.description = test_result_dict.get('description') + t.creation_date = str(test_result_dict.get('creation_date')) + t.details = test_result_dict.get('details') + + return t + + def format(self): + return { + "case_name": self.case_name, + "project_name": self.project_name, + "pod_id": self.pod_id, + "description": self.description, + "creation_date": self.creation_date, + "details": self.details, + } + + def format_http(self): + return { + "_id": str(self._id), + "case_name": self.case_name, + "project_name": self.project_name, + "pod_id": self.pod_id, + "description": self.description, + "creation_date": self.creation_date, + "details": self.details, + } |