Skip to content

Commit

Permalink
Configurable fields for requirements; more complete fields mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Sep 10, 2019
1 parent cd2b569 commit 91a7b91
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 43 deletions.
40 changes: 29 additions & 11 deletions dump2polarion/exporters/requirements_exporter.py
Expand Up @@ -7,14 +7,14 @@
"title": "requirement_complete",
"description": "Complete Requirement",
"approver-ids": "mkourim:approved",
"assignee-id": "mkourim",
"assignee": "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",
"dueDate": "2018-09-30",
"plannedIn": "planned_id1, planned_id2",
"initialEstimate": "1/4h",
"priority": "high",
"severity": "should_have",
"status": "status_id",
"reqtype": "functional",
},
{
Expand Down Expand Up @@ -53,7 +53,9 @@ class RequirementTransform:

FIELD_MAPPING = {
"assignee-id": "assignee",
"due-date": "dueDate",
"initial-estimate": "initialEstimate",
"planned-in-ids": "plannedIn",
"priority-id": "priority",
"severity-id": "severity",
"status-id": "status",
Expand All @@ -67,6 +69,15 @@ def __init__(self, config, transform_func=None):
config
)

default_fields = self.config.get("requirements_default_fields") or {}
default_fields = {k: utils.get_unicode_str(v) for k, v in default_fields.items() if v}
self.default_fields = utils.sorted_dict(default_fields)

def _fill_project_defaults(self, testcase_data):
filled = self.default_fields.copy()
filled.update(testcase_data)
return filled

def _run_transform_func(self, result):
"""Calls transform function on result."""
if self._transform_func:
Expand All @@ -91,6 +102,7 @@ def _fill_defaults(self, req_data):

def transform(self, req_data):
"""Transforms requirement data."""
req_data = self._fill_project_defaults(req_data)
req_data = self._fill_polarion_fields(req_data)
req_data = self._run_transform_func(req_data)
if not req_data:
Expand All @@ -114,6 +126,9 @@ def __init__(self, requirements_data, config, transform_func=None):
self._lookup_prop = ""
self.requirement_transform = RequirementTransform(config, transform_func)

self.known_custom_fields = set(self.requirement_transform.CUSTOM_FIELDS)
self.known_custom_fields.update(self.config.get("requirements_custom_fields") or ())

def _top_element(self):
"""Returns top XML element."""
attrs = {"project-id": self.config["polarion-project-id"]}
Expand Down Expand Up @@ -173,10 +188,13 @@ def _classify_data(self, req_data):
if not value:
continue
conv_key = key.replace("_", "-") # convert pythonic key_param to polarion 'key-param'
if conv_key in self.requirement_transform.REQ_DATA:
attrs[conv_key] = value
elif conv_key in self.requirement_transform.CUSTOM_FIELDS:
custom_fields[conv_key] = value
for key_variant in (conv_key, key):
if key_variant in self.requirement_transform.REQ_DATA:
attrs[key_variant] = value
elif key_variant in self.known_custom_fields:
custom_fields[key_variant] = value
if conv_key == key:
break

return attrs, custom_fields

Expand Down
20 changes: 13 additions & 7 deletions dump2polarion/exporters/testcases_exporter.py
Expand Up @@ -8,9 +8,9 @@
"title": "test_manual",
"description": "Manual tests with all supported fields.",
"approver-ids": "bossman mkourim:approved",
"assignee-id": "mkourim",
"due-date": "2018-09-30",
"initial-estimate": "1/4h",
"assignee": "mkourim",
"dueDate": "2018-09-30",
"initialEstimate": "1/4h",
"caseautomation": "manualonly",
"caseimportance": "high",
"caselevel": "component",
Expand All @@ -25,13 +25,13 @@
"automation_script": "https://gitlab.com/foo",
"testSteps": ["step1", "step2"],
"expectedResults": ["result1", "result2"],
"linked-items": "ITEM01",
"status-id": "proposed",
"linkedWorkItems": "ITEM01",
"status": "proposed",
},
{
"title": "test_minimal_param",
"params": ["param1", "param2"],
"linked-items": [{"id": "ITEM01", "role": "derived_from"}],
"linkedWorkItems": [{"id": "ITEM01", "role": "derived_from"}],
},
]
"""
Expand Down Expand Up @@ -62,7 +62,13 @@ class TestcaseTransform:
"status-id": None,
}

FIELD_MAPPING = {"assignee-id": "assignee", "initial-estimate": "initialEstimate"}
FIELD_MAPPING = {
"assignee-id": "assignee",
"due-date": "dueDate",
"initial-estimate": "initialEstimate",
"status-id": "status",
"linked-items": "linkedWorkItems",
}

CUSTOM_FIELDS = {
"arch": None,
Expand Down
30 changes: 22 additions & 8 deletions polarion_tools.yaml.template
Expand Up @@ -15,22 +15,23 @@ repo_address: https://github.com/project/repo

default_fields:
assignee: ""
casecomponent: ""
initialEstimate: 1m
caseautomation: automated
casecomponent: "-"
caseimportance: high
caselevel: component
caseposneg: positive
caseautomation: automated
testtype: functional
description: ""
expectedResults: ""
initialEstimate: ""
linkedWorkItems: ""
setup: ""
status: ""
subtype1: "-"
subtype2: "-"
tags: ""
setup: ""
teardown: ""
description: ""
linkedWorkItems: ""
testSteps: ""
expectedResults: ""
testtype: functional
title: ""
work_item_id: ""

Expand All @@ -48,6 +49,19 @@ custom_fields:
- testtype
- upstream

requirements_default_fields:
assignee: ""
dueDate: ""
initialEstimate: ""
plannedIn: ""
priority: ""
reqtype: "functional"
severity: ""
status: ""

requirements_custom_fields:
- reqtype

blacklisted_tests:
- 'cfme/tests/containers/'
- 'cfme/tests/openstack/'
Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Expand Up @@ -58,13 +58,16 @@
)
)

REQUIREMENTS_DEFAULT_FIELDS = OrderedDict((("reqtype", "system"),))

RHCF3_TESTCASE_PROPS = OrderedDict((("lookup-method", "name"),))

RHCF3_CONF = GENERIC_CONF.copy()
RHCF3_CONF["polarion-project-id"] = "RHCF3"
RHCF3_CONF["xunit_import_properties"] = RHCF3_XUNIT_PROPS
RHCF3_CONF["testcase_import_properties"] = RHCF3_TESTCASE_PROPS
RHCF3_CONF["default_fields"] = POLARION_DEFAULT_FIELDS
RHCF3_CONF["requirements_default_fields"] = REQUIREMENTS_DEFAULT_FIELDS
RHCF3_CONF["docstrings"] = VALID_CASELEVELS

CMP_CONF = GENERIC_CONF.copy()
Expand Down
14 changes: 7 additions & 7 deletions tests/data/polarion_tools.yaml
@@ -1,8 +1,8 @@
polarion-project-id : RHCF3
polarion-project-id: RHCF3
xunit_import_properties:
polarion-dry-run : false
polarion-testrun-status-id : inprogress
polarion-response-test : test
polarion_url : https://polarion.example.com/
username : user1
password : password1
polarion-dry-run: false
polarion-testrun-status-id: inprogress
polarion-response-test: test
polarion_url: https://polarion.example.com/
username: user1
password: password1
6 changes: 3 additions & 3 deletions tests/data/requirement_complete.xml
Expand Up @@ -5,7 +5,7 @@
<property name="prop2" value="val2"/>
<property name="lookup-method" value="name"/>
</properties>
<requirement approver-ids="sbulage:approved" assignee-id="mkourim" category-ids="CAT-01" due-date="2018-05-30" initial-estimate="1/4h" planned-in-ids="PROJ-01" priority-id="medium" severity-id="good_to_have" status-id="STAT-01">
<requirement approver-ids="sbulage:approved" assignee-id="mkourim" category-ids="CAT-01" due-date="2018-05-30" initial-estimate="1/4h" planned-in-ids="PROJ-01" priority-id="medium" severity-id="nice_to_have" status-id="STAT-01">
<title>req01</title>
<custom-fields>
<custom-field content="functional" id="reqtype"/>
Expand All @@ -15,13 +15,13 @@
<title>req02</title>
<description>requirement description</description>
<custom-fields>
<custom-field content="functional" id="reqtype"/>
<custom-field content="system" id="reqtype"/>
</custom-fields>
</requirement>
<requirement approver-ids="mkourim:approved" assignee-id="mkourim" priority-id="high" severity-id="should_have">
<title>req03</title>
<custom-fields>
<custom-field content="functional" id="reqtype"/>
<custom-field content="system" id="reqtype"/>
</custom-fields>
</requirement>
</requirements>
14 changes: 7 additions & 7 deletions tests/test_requirement_exporter.py
Expand Up @@ -15,14 +15,14 @@
(
("title", "req01"),
("approver-ids", "sbulage:approved"),
("assignee-id", "mkourim"),
("assignee", "mkourim"),
("category-ids", "CAT-01"),
("due-date", "2018-05-30"),
("planned-in-ids", "PROJ-01"),
("initial-estimate", "1/4h"),
("priority-id", "medium"),
("severity-id", "good_to_have"),
("status-id", "STAT-01"),
("dueDate", "2018-05-30"),
("plannedIn", "PROJ-01"),
("initialEstimate", "1/4h"),
("priority", "medium"),
("severity", "nice_to_have"),
("status", "STAT-01"),
("reqtype", "functional"),
)
),
Expand Down

0 comments on commit 91a7b91

Please sign in to comment.