summaryrefslogtreecommitdiffstats
path: root/utils/test/result_collection_api/resources/project_models.py
blob: 895fc3e5eaae18f03748c11f411dd942584bf8f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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