Skip to content

Commit

Permalink
feat: Respect automation_script and repo_address full path
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
mkoura committed Sep 26, 2019
1 parent c7f00cb commit a85d971
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
32 changes: 27 additions & 5 deletions dump2polarion/exporters/testcases_exporter.py
Expand Up @@ -39,6 +39,7 @@
import datetime
import logging
import re
import urllib

from lxml import etree

Expand Down Expand Up @@ -102,21 +103,42 @@ def __init__(self, config, transform_func=None):
default_fields = self.config.get("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)
self.repo_address = self._get_full_repo_address(self.config.get("repo_address"))

@staticmethod
def _get_full_repo_address(repo_address):
"""Makes sure the repo address is complete path in repository.
>>> TestcaseTransform._get_full_repo_address("https://gitlab.com/somerepo")
'https://gitlab.com/somerepo/blob/master/'
>>> TestcaseTransform._get_full_repo_address("https://github.com/otherrepo/blob/branch/")
'https://github.com/otherrepo/blob/branch/'
>>> TestcaseTransform._get_full_repo_address(None)
"""
if not repo_address:
return None

if "/blob/" not in repo_address:
# the master here should probably link the latest "commit" eventually
repo_address = "{}/blob/master".format(repo_address)

# make sure the / is present at the end of address
repo_address = "{}/".format(repo_address.rstrip("/ "))

return repo_address

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

def _fill_automation_repo(self, testcase_data):
repo_address = self.config.get("repo_address")
automation_script = testcase_data.get("automation_script")
if not (repo_address and automation_script):
if not (self.repo_address and automation_script) or automation_script.startswith("http"):
return testcase_data

# the master here should probably link the latest "commit" eventually
testcase_data["automation_script"] = "{}/blob/master/{}".format(
repo_address, automation_script
testcase_data["automation_script"] = urllib.parse.urljoin(
self.repo_address, automation_script
)
return testcase_data

Expand Down
3 changes: 2 additions & 1 deletion tests/data/testcase_complete_cfme.xml
Expand Up @@ -38,13 +38,14 @@ Manual tests with many supported fields.
</testcase>
<testcase id="test_minimal_param" initial-estimate="1m">
<title>test_minimal_param</title>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;&lt;a href="https://github.com/somerepo/blob/somebranch/file#L83"&gt;Test Source&lt;/a&gt;</description>
<test-steps>
<test-step>
<test-step-column id="step"/>
</test-step>
</test-steps>
<custom-fields>
<custom-field content="https://github.com/somerepo/blob/somebranch/file#L83" id="automation_script"/>
<custom-field content="automated" id="caseautomation"/>
<custom-field content="high" id="caseimportance"/>
<custom-field content="component" id="caselevel"/>
Expand Down
3 changes: 2 additions & 1 deletion tests/data/testcase_complete_cfme_param.xml
Expand Up @@ -38,7 +38,7 @@ Manual tests with many supported fields.
</testcase>
<testcase id="test_minimal_param" initial-estimate="1m">
<title>test_minimal_param</title>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;&lt;a href="https://github.com/somerepo/blob/somebranch/file#L83"&gt;Test Source&lt;/a&gt;</description>
<test-steps>
<test-step>
<test-step-column id="step">
Expand All @@ -48,6 +48,7 @@ Manual tests with many supported fields.
</test-step>
</test-steps>
<custom-fields>
<custom-field content="https://github.com/somerepo/blob/somebranch/file#L83" id="automation_script"/>
<custom-field content="automated" id="caseautomation"/>
<custom-field content="high" id="caseimportance"/>
<custom-field content="component" id="caselevel"/>
Expand Down
3 changes: 2 additions & 1 deletion tests/data/testcase_fields_cfme.xml
Expand Up @@ -39,13 +39,14 @@ Manual tests with many supported fields.
</testcase>
<testcase id="test_minimal_param">
<title>test_minimal_param</title>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;</description>
<description>empty-description-placeholder&lt;br id="id123"/&gt;&lt;br/&gt;&lt;a href="https://github.com/somerepo/blob/somebranch/file#L83"&gt;Test Source&lt;/a&gt;</description>
<test-steps>
<test-step>
<test-step-column id="step"/>
</test-step>
</test-steps>
<custom-fields>
<custom-field content="https://github.com/somerepo/blob/somebranch/file#L83" id="automation_script"/>
<custom-field content="automated" id="caseautomation"/>
<custom-field content="medium" id="caseimportance"/>
<custom-field content="component" id="caselevel"/>
Expand Down
1 change: 1 addition & 0 deletions tests/test_testcase_exporter.py
Expand Up @@ -44,6 +44,7 @@
("params", ["param1", "param2"]),
("linked-items-lookup-method", "name"),
("linked-items", [{"id": "ITEM01", "role": "derived_from"}]),
("automation_script", "https://github.com/somerepo/blob/somebranch/file#L83"),
)
),
]
Expand Down

0 comments on commit a85d971

Please sign in to comment.