Skip to content

Commit

Permalink
Always set testcase ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoura committed Jan 28, 2019
1 parent 3f1fcde commit 8c76bf5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
49 changes: 36 additions & 13 deletions dump2polarion/exporters/testcases_exporter.py
Expand Up @@ -159,20 +159,40 @@ def _fill_lookup_prop(self, testcases_properties):
testcases_properties, "property", {"name": "lookup-method", "value": self._lookup_prop}
)

def _check_lookup_prop(self, testcase_id, testcase_title):
"""Checks that selected lookup property can be used for this testcase."""
def _set_lookup_prop(self, testcase_data):
"""Set lookup property based on processed testcases if not configured."""
if self._lookup_prop:
if not testcase_id and self._lookup_prop != "name":
return False
if not testcase_title and self._lookup_prop == "name":
return False
return

if testcase_data.get("id"):
self._lookup_prop = "id"
elif testcase_data.get("title"):
self._lookup_prop = "name"
else:
if testcase_id:
self._lookup_prop = "id"
elif testcase_title:
self._lookup_prop = "name"
return

logger.debug("Setting lookup method for testcases to `%s`", self._lookup_prop)

def _check_lookup_prop(self, testcase_data):
"""Checks that selected lookup property can be used for this testcase."""
if not self._lookup_prop:
return False

if not testcase_data.get("id") and self._lookup_prop != "name":
return False
if not testcase_data.get("title") and self._lookup_prop == "name":
return False
return True

def _get_testcase_id(self, testcase_data):
"""Returns testcase id when possible."""
testcase_id = testcase_data.get("id")
if testcase_id:
return testcase_id
if self._lookup_prop != "name":
return None
return testcase_data.get("title")

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

Expand Down Expand Up @@ -298,16 +318,19 @@ def _testcase_element(self, parent_element, testcase_data):
if not testcase_data:
return

testcase_id = testcase_data.get("id")
testcase_title = testcase_data.get("title")

if not self._check_lookup_prop(testcase_id, testcase_title):
self._set_lookup_prop(testcase_data)
if not self._check_lookup_prop(testcase_data):
logger.warning(
"Skipping testcase `%s`, data missing for selected lookup method",
testcase_id or testcase_title,
testcase_data.get("id") or testcase_title,
)
return

# make sure that ID is set even for "name" lookup method
testcase_data["id"] = self._get_testcase_id(testcase_data)

attrs, custom_fields = self._classify_data(testcase_data)
attrs, custom_fields = self._fill_defaults(attrs, custom_fields)

Expand Down
34 changes: 23 additions & 11 deletions dump2polarion/exporters/xunit_exporter.py
Expand Up @@ -158,18 +158,29 @@ def _get_verdict(result):
return None
return verdict

def _check_lookup_prop(self, testcase_id, testcase_title):
"""Checks that selected lookup property can be used for this testcase."""
def _set_lookup_prop(self, result_data):
"""Set lookup property based on processed testcases if not configured."""
if self._lookup_prop:
if not testcase_id and self._lookup_prop != "name":
return False
if not testcase_title and self._lookup_prop == "name":
return False
return

if result_data.get("id"):
self._lookup_prop = "id"
elif result_data.get("title"):
self._lookup_prop = "name"
else:
if testcase_id:
self._lookup_prop = "id"
elif testcase_title:
self._lookup_prop = "name"
return

logger.debug("Setting lookup method for xunit to `%s`", self._lookup_prop)

def _check_lookup_prop(self, result_data):
"""Checks that selected lookup property can be used for this testcase."""
if not self._lookup_prop:
return False

if not result_data.get("id") and self._lookup_prop != "name":
return False
if not result_data.get("title") and self._lookup_prop == "name":
return False
return True

@staticmethod
Expand Down Expand Up @@ -238,7 +249,8 @@ def _gen_testcase(self, parent_element, result, records):
testcase_id = result.get("id")
testcase_title = result.get("title")

if not self._check_lookup_prop(testcase_id, testcase_title):
self._set_lookup_prop(result)
if not self._check_lookup_prop(result):
logger.warning(
"Skipping testcase `%s`, data missing for selected lookup method",
testcase_id or testcase_title,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/testcase_complete_cfme.xml
Expand Up @@ -34,7 +34,7 @@
<linked-work-item workitem-id="ITEM01" role-id="verifies"/>
</linked-work-items>
</testcase>
<testcase>
<testcase id="test_minimal_param">
<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 @@ -34,7 +34,7 @@
<linked-work-item workitem-id="ITEM01" role-id="verifies"/>
</linked-work-items>
</testcase>
<testcase>
<testcase id="test_minimal_param">
<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_fields_cfme.xml
Expand Up @@ -35,7 +35,7 @@
<linked-work-item workitem-id="ITEM01" role-id="verifies"/>
</linked-work-items>
</testcase>
<testcase>
<testcase id="test_minimal_param">
<title>test_minimal_param</title>
<description>&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<test-steps>
Expand Down

0 comments on commit 8c76bf5

Please sign in to comment.