Skip to content

Commit

Permalink
Testcases support
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Jul 10, 2018
1 parent 85a248d commit 7785fc9
Show file tree
Hide file tree
Showing 37 changed files with 675 additions and 127 deletions.
15 changes: 15 additions & 0 deletions dump2polarion/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ def _populate_urls(config):
config[key] = '{}/{}'.format(base_url, url)


def _set_project_id(config):
if config.get('polarion-project-id'):
return
# use legacy configuration if available
xunit_project = config.get('xunit_import_properties', {}).get('polarion-project-id')
if xunit_project:
config['polarion-project-id'] = xunit_project
logger.warning(
'Loading the "polarion-project-id" from legacy configuration "xunit_import_properties"'
' instead of from top level')
else:
raise Dump2PolarionException('The "polarion-project-id" key is missing in the config file')


def get_config(config_file=None):
"""Loads config file and returns its content."""
default_conf = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'dump2polarion.yaml')
Expand Down Expand Up @@ -100,6 +114,7 @@ def get_config(config_file=None):
'Failed to load the \'{}\' config file: {}'.format(user_conf, err))

_populate_urls(config_settings)
_set_project_id(config_settings)
_check_config(config_settings)

return config_settings
5 changes: 2 additions & 3 deletions dump2polarion/dump2polarion.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
polarion-project-id : RHCF3
xunit_import_properties:
polarion-project-id : RHCF3
polarion-dry-run : false
polarion-testrun-status-id : inprogress
auth_url: null
auth_url : null
8 changes: 5 additions & 3 deletions dump2polarion/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ def set_lookup_method(xml_root, value):
raise Dump2PolarionException(_NOT_EXPECTED_FORMAT_MSG)


def set_dry_run(xml_root):
def set_dry_run(xml_root, value=False):
"""Sets dry-run so records are not updated, only log file is produced."""
value_str = str(value).lower()
assert value_str in ('true', 'false')
if xml_root.tag == 'testsuites':
_set_property(xml_root, 'polarion-dry-run', 'true')
_set_property(xml_root, 'polarion-dry-run', value_str)
elif xml_root.tag in ('testcases', 'requirements'):
_set_property(xml_root, 'dry-run', 'true')
_set_property(xml_root, 'dry-run', value_str)
else:
raise Dump2PolarionException(_NOT_EXPECTED_FORMAT_MSG)
57 changes: 40 additions & 17 deletions dump2polarion/requirements_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@
# pylint: disable=c-extension-no-member
"""
Creates a Requirement XML file for submitting to the Polarion Importer.
Example of input requirements_data:
requirements_data = [
{
'title': 'requirement_complete',
'description': 'Complete Requirement',
'approver-ids': 'mkourim:approved',
'assignee-id': 'mkourim',
'category-ids': 'category_id1, category_id2',
'due-date': '2018-09-30',
'planned-in-ids': 'planned_id1, planned_id2',
'initial-estimate': '1/4h',
'priority-id': 'high',
'severity-id': 'should_have',
'status-id': 'status_id',
'reqtype': 'functional',
},
{
'title': 'requirement_minimal',
},
]
"""

from __future__ import absolute_import, unicode_literals

import datetime

from collections import OrderedDict

import six

from lxml import etree
Expand All @@ -19,20 +42,20 @@
class RequirementExport(object):
"""Exports requirements data into XML representation."""

REQ_DATA = {
'approver-ids': None,
'assignee-id': None,
'category-ids': None,
'due-date': None,
'planned-in-ids': None,
'initial-estimate': None,
'priority-id': 'high',
'severity-id': 'should_have',
'status-id': None,
}
CUSTOM_FIELDS = {
'reqtype': 'functional',
}
REQ_DATA = OrderedDict((
('approver-ids', None),
('assignee-id', None),
('category-ids', None),
('due-date', None),
('initial-estimate', None),
('planned-in-ids', None),
('priority-id', 'high'),
('severity-id', 'should_have'),
('status-id', None),
))
CUSTOM_FIELDS = OrderedDict((
('reqtype', 'functional'),
))

def __init__(self, requirements_data, config, transform_func=None):
self.requirements_data = requirements_data
Expand All @@ -48,7 +71,7 @@ def _transform_result(self, result):

def _top_element(self):
"""Returns top XML element."""
attrs = {'project-id': self.config['xunit_import_properties']['polarion-project-id']}
attrs = {'project-id': self.config['polarion-project-id']}
document_relative_path = self.config.get('requirements-document-relative-path')
if document_relative_path:
attrs['document-relative-path'] = document_relative_path
Expand Down Expand Up @@ -100,8 +123,8 @@ def _check_lookup_prop(self, req_id, req_title):
return True

def _classify_data(self, req_data):
attrs = {}
custom_fields = {}
attrs = OrderedDict()
custom_fields = OrderedDict()

for key, value in six.iteritems(req_data):
if not value:
Expand Down
8 changes: 4 additions & 4 deletions dump2polarion/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ def _get_credentials(config, **kwargs):

# pylint: disable=too-many-arguments
def submit(xml_str=None, xml_file=None, xml_root=None, config=None, session=None,
dry_run=False, **kwargs):
dry_run=None, **kwargs):
"""Submits data to the Polarion Importer."""
try:
config = config or configuration.get_config()
xml_root = _get_xml_root(xml_root, xml_str, xml_file)
credentials = _get_credentials(config, **kwargs)
submit_target = _get_submit_target(xml_root, config)
properties.xunit_fill_testrun_id(xml_root, kwargs.get('testrun_id'))
if dry_run:
properties.set_dry_run(xml_root)
if dry_run is not None:
properties.set_dry_run(xml_root, dry_run)
xml_input = utils.etree_to_string(xml_root)
session = session or utils.get_session(credentials, config)
except Dump2PolarionException as err:
Expand All @@ -166,7 +166,7 @@ def submit(xml_str=None, xml_file=None, xml_root=None, config=None, session=None

# pylint: disable=too-many-arguments
def submit_and_verify(xml_str=None, xml_file=None, xml_root=None, config=None, session=None,
dry_run=False, **kwargs):
dry_run=None, **kwargs):
"""Submits data to the Polarion Importer and checks that it was imported."""
try:
config = config or configuration.get_config()
Expand Down

0 comments on commit 7785fc9

Please sign in to comment.