summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/cli/results.py
blob: 56ea71fd1f976bc1968fd3aac204129c137836c1 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import json

from testapiclient.utils import command
from testapiclient.utils import urlparse


def results_url():
    return urlparse.resource_join('results')


def result_url(parsed_args):
    return urlparse.path_join(results_url(), parsed_args.result_id)


class ResultGet(command.Lister):

    def get_parser(self, prog_name):
        parser = super(ResultGet, self).get_parser(prog_name)
        parser.add_argument('-case',
                            help='Search results using tesetcase')
        parser.add_argument('-build-tag',
                            help='Search results using build tag')
        parser.add_argument('-from',
                            help='Search results using from date')
        parser.add_argument('-last',
                            help='Search results using last date')
        parser.add_argument('-scenario',
                            help='Search results using scenario')
        parser.add_argument('-period',
                            help='Search results using period')
        parser.add_argument('-project',
                            help='Search results using project')
        parser.add_argument('-to',
                            help='Search results using to')
        parser.add_argument('---version',
                            help='Search results using version')
        parser.add_argument('-criteria',
                            help='Search results using version')
        parser.add_argument('-installer',
                            help='Search results using installer')
        parser.add_argument('-pod',
                            help='Search results using pod')
        parser.add_argument('-page',
                            help='Search results using page')
        return parser

    def take_action(self, parsed_args):
        columns = (
            '_id',
            'pod_name',
            'project_name',
            'case_name',
            'installer',
            'version',
            'scenario',
            'criteria',
            'start_date'
        )
        data = self.app.client_manager.get(
            urlparse.query_by(results_url(),
                              ['case', 'build_tag', 'from', 'last',
                               'scenario', 'period', 'project',
                               'to', 'version',
                               'criteria', 'installer', 'pod', 'page'],
                              parsed_args))
        return self.format_output(columns, data.get('results', []))


class ResultGetOne(command.ShowOne):

    def get_parser(self, prog_name):
        parser = super(ResultGetOne, self).get_parser(prog_name)
        parser.add_argument('result_id',
                            help='Search result by result id')
        return parser

    def take_action(self, parsed_args):
        return self.format_output(
            self.app.client_manager.get(result_url(parsed_args)))


class ResultCreate(command.ShowOne):

    def get_parser(self, prog_name):
        parser = super(ResultCreate, self).get_parser(prog_name)
        parser.add_argument('result',
                            type=json.loads,
                            help='Result create request format:\n'
                                 '\'{"project_name" : "","scenario" : "",'
                                 '"stop_date" : "", "case_name" : "",'
                                 '"build_tag" : "", "version" : "",'
                                 '"pod_name" : "" , "criteria" : "",'
                                 '"installer" : "", "start_date" : "",'
                                 '"details" : ""}\'')
        return parser

    def take_action(self, parsed_args):
        return self.format_output(
            self.app.client_manager.post(
                results_url(), parsed_args.result))