diff options
author | 2016-05-19 18:13:27 +0800 | |
---|---|---|
committer | 2016-05-19 18:18:07 +0800 | |
commit | 09f38fb67b1caeb4ccd33b83120842fbad306f78 (patch) | |
tree | 3331bf5af2add086548f8d4cec12f9f154fb0df1 /result_collection_api/resources/project_models.py | |
parent | 40c340fadbbcb1be66f011759f7daa3bb0e3927e (diff) |
add unittests of project & refactor response
post body: {'href':'<http://ip:8000/pods/pod_name >'}
get body: Pod/Project
list body: list of Pod/Project
update body: Pod/Project
delete: no body
JIRA: FUNCTEST-253
Change-Id: I28c6f5b35d8909d827f2f803197d95be4abd44bb
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'result_collection_api/resources/project_models.py')
-rw-r--r-- | result_collection_api/resources/project_models.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/result_collection_api/resources/project_models.py b/result_collection_api/resources/project_models.py new file mode 100644 index 0000000..895fc3e --- /dev/null +++ b/result_collection_api/resources/project_models.py @@ -0,0 +1,67 @@ +__author__ = '__serena__' + + +class ProjectCreateRequest(object): + def __init__(self, name='', description=''): + self.name = name + self.description = description + + def format(self): + return { + "name": self.name, + "description": self.description, + } + + +class Project: + """ Describes a test project""" + + def __init__(self): + self._id = None + self.name = None + self.description = None + self.creation_date = None + + @staticmethod + def from_dict(res_dict): + + if res_dict is None: + return None + + t = Project() + t._id = res_dict.get('_id') + t.creation_date = res_dict.get('creation_date') + t.name = res_dict.get('name') + t.description = res_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): + return { + "_id": str(self._id), + "name": self.name, + "description": self.description, + "creation_date": str(self.creation_date), + } + + +class Projects(object): + def __init__(self, projects=list()): + self.projects = projects + + @staticmethod + def from_dict(res_dict): + if res_dict is None: + return None + + res = Projects() + for project in res_dict.get('projects'): + res.projects.append(Project.from_dict(project)) + return res |