-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
57 lines (43 loc) · 2.11 KB
/
config.py
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
import argparse
class Config:
def __init__(self, mode, project_code, token, output, testrun_id, input):
self.input = input
self.mode = mode
self.project_code = project_code
self.token = token
self.output = output
self.testrun_id = testrun_id
class ConfigManager:
def __init__(self):
self.__parser = argparse.ArgumentParser()
self.__add_arguments()
self.__parse_arguments()
self.__validate_config()
def __add_arguments(self):
self.__parser.add_argument('-m', '--mode', default="validate", type=str,
help='Mode of operation: prepare or validate')
self.__parser.add_argument('-pc', '--project-code', type=str,
help='Code of Qase project', required=True)
self.__parser.add_argument('-t', '--token', type=str,
help='Token for Qase API', required=True)
self.__parser.add_argument('-ti', '--testrun-id', type=str,
help='Test run id for Qase API', required=True)
self.__parser.add_argument('-o', '--output', type=str,
help='Output file for results')
self.__parser.add_argument('-i', '--input', type=str,
help='Input file for results')
def __parse_arguments(self):
args = self.__parser.parse_args()
self.__config = Config(args.mode, args.project_code.upper(), args.token, args.output, args.testrun_id,
args.input)
def __validate_config(self):
if self.__config.mode not in ["prepare", "validate"]:
raise ValueError("Mode must be either 'prepare' or 'validate'")
if self.__config.mode == "prepare":
if not self.__config.output:
raise ValueError("Output file is required then mode is 'prepare'")
else:
if not self.__config.input:
raise ValueError("Input file is required then mode is 'validate'")
def get_config(self) -> Config:
return self.__config