Skip to content

Commit

Permalink
Map fields used by importers to fields used by Polarion
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Aug 30, 2019
1 parent 3fb2b37 commit 9335aa7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions dump2polarion/exporters/requirements_exporter.py
Expand Up @@ -55,6 +55,14 @@ class RequirementTransform(object):
"status-id": None,
}

FIELD_MAPPING = {
"assignee-id": "assignee",
"initial-estimate": "initialEstimate",
"priority-id": "priority",
"severity-id": "severity",
"status-id": "status",
}

CUSTOM_FIELDS = {"reqtype": "functional"}

def __init__(self, config, transform_func=None):
Expand All @@ -69,6 +77,15 @@ def _run_transform_func(self, result):
result = self._transform_func(result)
return result or None

def _fill_polarion_fields(self, req_data):
"""Sets importer field value from polarion field if available."""
for importer_field, polarion_field in self.FIELD_MAPPING.items():
polarion_value = req_data.get(polarion_field)
xml_value = req_data.get(importer_field)
if polarion_value and not xml_value:
req_data[importer_field] = polarion_value
return req_data

def _fill_defaults(self, req_data):
for defaults in self.REQ_DATA, self.CUSTOM_FIELDS:
for key, value in six.iteritems(defaults):
Expand All @@ -78,6 +95,7 @@ def _fill_defaults(self, req_data):

def transform(self, req_data):
"""Transforms requirement data."""
req_data = self._fill_polarion_fields(req_data)
req_data = self._run_transform_func(req_data)
if not req_data:
return None
Expand Down
12 changes: 12 additions & 0 deletions dump2polarion/exporters/testcases_exporter.py
Expand Up @@ -64,6 +64,8 @@ class TestcaseTransform(object):
"initial-estimate": None,
}

FIELD_MAPPING = {"assignee-id": "assignee", "initial-estimate": "initialEstimate"}

CUSTOM_FIELDS = {
"arch": None,
"automation_script": None,
Expand Down Expand Up @@ -120,6 +122,15 @@ def _run_transform_func(self, testcase_data):
testcase_data = self._transform_func(testcase_data)
return testcase_data or None

def _fill_polarion_fields(self, testcase_data):
"""Sets importer field value from polarion field if available."""
for importer_field, polarion_field in self.FIELD_MAPPING.items():
polarion_value = testcase_data.get(polarion_field)
xml_value = testcase_data.get(importer_field)
if polarion_value and not xml_value:
testcase_data[importer_field] = polarion_value
return testcase_data

def _fill_defaults(self, testcase_data):
for defaults in self.TESTCASE_DATA, self.CUSTOM_FIELDS:
for key, value in six.iteritems(defaults):
Expand All @@ -131,6 +142,7 @@ def transform(self, testcase_data):
"""Transforms testcase data."""
testcase_data = self._fill_project_defaults(testcase_data)
testcase_data = self._fill_automation_repo(testcase_data)
testcase_data = self._fill_polarion_fields(testcase_data)
testcase_data = self._run_transform_func(testcase_data)
if not testcase_data:
return None
Expand Down
2 changes: 1 addition & 1 deletion tests/data/testcase_complete_cfme.xml
Expand Up @@ -36,7 +36,7 @@ Manual tests with many supported fields.
<linked-work-item workitem-id="ITEM01" role-id="verifies"/>
</linked-work-items>
</testcase>
<testcase id="test_minimal_param">
<testcase id="test_minimal_param" initial-estimate="1m">
<title>test_minimal_param</title>
<description>&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<test-steps>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/testcase_complete_cfme_param.xml
Expand Up @@ -36,7 +36,7 @@ Manual tests with many supported fields.
<linked-work-item workitem-id="ITEM01" role-id="verifies"/>
</linked-work-items>
</testcase>
<testcase id="test_minimal_param">
<testcase id="test_minimal_param" initial-estimate="1m">
<title>test_minimal_param</title>
<description>&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<test-steps>
Expand Down

0 comments on commit 9335aa7

Please sign in to comment.