Skip to content

Commit

Permalink
Fix paths for data files from package.
Browse files Browse the repository at this point in the history
Change-Id: Ic6d9b8f40b907763474ba1c94d2086f5db4a45ad
  • Loading branch information
Ilya Bumarskov committed Aug 28, 2020
1 parent 419d3d9 commit 694449c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 26 deletions.
78 changes: 62 additions & 16 deletions testrail_reporter/cmd/reporter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import logging
import json
import logging
import pkg_resources

from testrail_reporter.lib.config import Config
from testrail_reporter.lib.settings import TRR_LOG_FILE, TRR_LOG_LEVEL
Expand Down Expand Up @@ -49,13 +50,26 @@ def publish(args, config):
LOG.debug('Testrail Test Run: "{0}"'.format(args.tr_run))
LOG.debug('Suite name: "{0}"'.format(args.tr_suite))
LOG.debug('Milestone: "{0}"'.format(args.tr_milestone))

if not args.tr_result_attrs:
rpath = '/'.join(('etc', 'tr_result_attrs.yaml'))
tr_result_attrs = pkg_resources.resource_filename("testrail_reporter",
rpath)
else:
tr_result_attrs = args.tr_result_attrs
if not args.tr_result_map:
rpath = '/'.join(('etc/maps', args.map, 'result_template.yaml'))
tr_result_map = pkg_resources.resource_filename("testrail_reporter",
rpath)
else:
tr_result_map = args.tr_result_attrs
if args.tr_conf is not None:
tr_conf = json.loads(args.tr_conf.replace("\'", '"'))
else:
tr_conf = None

report = ReportParser(tr_result_attrs=args.tr_result_attrs,
tr_result_map=args.tr_result_map)
report = ReportParser(tr_result_attrs=tr_result_attrs,
tr_result_map=tr_result_map)
results = report.get_result_list(args.report_path)

reporter = TestRailReporter(url=config.url,
Expand All @@ -75,7 +89,21 @@ def update_suite(args, config):
log_settings(args, config)
LOG.debug('Suite name: "{0}"'.format(args.tr_suite))

tc_parser = TestCaseParser(case_map=args.testcase_map)
if not args.tr_case_attrs:
rpath = '/'.join(('etc', 'tr_case_attrs.yaml'))
tr_case_attrs = pkg_resources.resource_filename("testrail_reporter",
rpath)
else:
tr_case_attrs = args.tr_case_attrs
if not args.tr_case_map:
rpath = '/'.join(('etc/maps', args.map, 'case_template.yaml'))
tr_case_map = pkg_resources.resource_filename("testrail_reporter",
rpath)
else:
tr_case_map = args.tr_result_attrs

tc_parser = TestCaseParser(tr_case_attrs=tr_case_attrs,
tr_case_map=tr_case_map)
tc_list = tc_parser.get_tc_list(args.tc_list_path)

reporter = TestRailReporter(url=config.url,
Expand Down Expand Up @@ -148,13 +176,21 @@ def main():
)
parser_b.add_argument(
'--result-attrs', dest='tr_result_attrs',
default='testrail_reporter/etc/tr_result_attrs.yaml',
help='Custom result attributes'
default=None,
help='Set path to config file with custom result attributes '
'(.yaml format).'
)
parser_b.add_argument(
'--map', dest='map',
default='tempest',
help='Use predefined map for parsing attributes. Supported values:'
'tempest, pytest'
)
parser_b.add_argument(
'--result-map', dest='tr_result_map',
default='testrail_reporter/etc/maps/tempest/result_template.yaml',
help='Custom result map'
default=None,
help='Set path to config file with custom result map. '
'Note: this parameter overrides predefined map parameter.'
)
parser_b.set_defaults(func=publish)
# ================================ update ================================
Expand All @@ -172,18 +208,28 @@ def main():
'-s', dest='tr_suite', default=None,
help='TestRail Suite name.'
)
parser_b.add_argument(
'--case-attrs', dest='tr_case_attrs',
default=None,
help='Set path to config file with custom case attributes '
'(.yaml format).'
)
parser_c.add_argument(
'--map', dest='map',
default='tempest',
help='Use predefined map for parsing case attributes. Supported '
'values: tempest, pytest'
)
parser_c.add_argument(
'--tc-map', dest='testcase_map',
default='testrail_reporter/etc/maps/tempest/case_template.yaml',
help='TestCase map'
'--tc-map', dest='tr_case_map',
default=None,
help='Set path to config file with custom case map. '
'Note: this parameter overrides predefined map parameter.'
)
parser_c.set_defaults(func=update_suite)
# =========================================================================
try:
args = parser.parse_args()
args.func(args, config)
except AttributeError:
parser.print_help()
args = parser.parse_args()
args.func(args, config)


if __name__ == "__main__":
Expand Down
15 changes: 7 additions & 8 deletions testrail_reporter/lib/testcaseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@


class TestCaseParser(object):
def __init__(self,
tr_case_attrs='etc/tr_case_attrs.yaml',
case_map='etc/maps/pytest/case_template.yaml'):
def __init__(self, tr_case_attrs, tr_case_map):
with open(tr_case_attrs, 'r') as stream:
self.tr_case_attrs = yaml.safe_load(stream)
with open(case_map, 'r') as stream:
self.case_map = yaml.safe_load(stream)
with open(tr_case_map, 'r') as stream:
self.tr_case_map = yaml.safe_load(stream)

def get_tc_list(self, tc_list_file):
with open(tc_list_file, 'r') as stream:
tc_raw_list = [line.rstrip('\n') for line in stream]
tc_list = []
for i in tc_raw_list:
tc = copy.copy(self.tr_case_attrs)
tc['title'] = perform_actions(i, self.case_map['title']['actions'])
tc['title'] = perform_actions(
i, self.tr_case_map['title']['actions'])
assert tc['title'] is not None, "Title shouldn't be empty"
section_id = perform_actions(i,
self.case_map['section']['actions'])
section_id = perform_actions(
i, self.tr_case_map['section']['actions'])
if section_id:
tc['section_id'] = section_id
tc_list.append(tc)
Expand Down
8 changes: 6 additions & 2 deletions testrail_reporter/lib/testrailreporter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import logging
import pkg_resources
import yaml

from testrail_reporter.lib.testrailproject import TestRailProject
Expand All @@ -9,9 +10,12 @@

class TestRailReporter:

def __init__(self, url, user, password, project_name,
attr2id_map='testrail_reporter/etc/attrs2id.yaml'):
def __init__(self, url, user, password, project_name, attr2id_map=None):
self.project = TestRailProject(url, user, password, project_name)
if not attr2id_map:
rpath = '/'.join(('etc', 'attrs2id.yaml'))
attr2id_map = pkg_resources.resource_filename("testrail_reporter",
rpath)
with open(attr2id_map, 'r') as stream:
self.attr2id_map = yaml.safe_load(stream)

Expand Down

0 comments on commit 694449c

Please sign in to comment.