Skip to content

Commit 0b843e3

Browse files
authored
Merge pull request #24 from Brian-Williams/RobotTestLinkHelper
WIP: Add RobotTestLinkHelper
2 parents a514397 + 0729c92 commit 0b843e3

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

Diff for: robot/docparser.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import re
2+
3+
4+
class DocTestParser(object):
5+
"""Find all externaltestcaseid's in a test's docstring.
6+
7+
If your externaltestcaseid prefix is abc and the test has 'abc-123' in it's docstring.
8+
`DocTestParser('abc').get_testcases(test)` would return `['abc-123']`.
9+
"""
10+
def __init__(self, doc_matcher=None, doc_matchers=None):
11+
"""
12+
:param doc_matchers: List of regex to find in docstring
13+
"""
14+
self.doc_matchers = doc_matchers if doc_matchers is not None else []
15+
if doc_matcher:
16+
self.doc_matchers.append(doc_matcher)
17+
18+
def get_testcases(self, test):
19+
testcases = set()
20+
for matcher in self.doc_matchers:
21+
testcases |= set(re.findall('{}-\d+'.format(matcher), test.doc))
22+
return testcases

Diff for: robot/robottestlinkhelper.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from testlink import TestLinkHelper
2+
from robot.libraries.BuiltIn import BuiltIn
3+
4+
5+
reportTCResultParams = [
6+
'testcaseid', 'testplanid', 'buildname', 'status', 'notes', 'testcaseexternalid', 'buildid', 'platformid',
7+
'platformname', 'guess', 'bugid', 'custumfields', 'overwrite', 'user', 'execduration', 'timestamp', 'steps',
8+
'devkey']
9+
robot_report_params = {str(param): 'testlink' + str(param) for param in reportTCResultParams}
10+
11+
12+
def setdefault_if_not_none(di, key, val):
13+
if key not in di:
14+
if val is not None:
15+
di[key] = val
16+
17+
18+
class RobotTestLinkHelper(TestLinkHelper):
19+
"""
20+
We preface all testlink inputs with 'testlink'.
21+
22+
So, to pass the serverurl as a variable in a robot test set the variable ${testlinkserverurl}.
23+
24+
This is to avoid polluting the robot framework variable namespace with common variable names.
25+
"""
26+
def _get_param_from_robot(self, robot_variable):
27+
"""Returns the found robot variable, defaults to None."""
28+
return BuiltIn().get_variable_value("${" + str(robot_variable) + "}")
29+
30+
def _get_missing_params_from_robot_variables(self, param_dict):
31+
for testlink_param, robot_variable in robot_report_params.items():
32+
setdefault_if_not_none(param_dict, testlink_param, self._get_param_from_robot(robot_variable))
33+
34+
def _setParamsFromRobot(self):
35+
"""
36+
fill empty slots from robot variables
37+
_server_url <- TESTLINK_API_PYTHON_SERVER_URL <- robot_variable`testlinkserverurl`
38+
_devkey <- TESTLINK_API_PYTHON_DEVKEY <- robot_variable`testlinkdevkey`
39+
_proxy <- http_proxy <- robot_variable`testlinkproxy`
40+
41+
If robot variables are not defined, values are kept as None for other _setParams* to handle.
42+
"""
43+
if self._server_url is None:
44+
self._server_url = self._get_param_from_robot('testlinkserverurl')
45+
if self._devkey is None:
46+
self._devkey = self._get_param_from_robot('testlinkdevkey')
47+
if not self._proxy:
48+
self._proxy = self._get_param_from_robot('testlinkproxy')
49+
50+
def _setParams(self):
51+
"""fill slots _server_url, _devkey and _proxy
52+
Priority:
53+
1. init args
54+
2. robot variables
55+
2. environment variables
56+
3. default values
57+
"""
58+
self._setParamsFromRobot()
59+
super(RobotTestLinkHelper, self)._setParams()

Diff for: src/testlink/testlinkhelper.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ def __init__(self, server_url=None, devkey=None, proxy=None):
7777
self._server_url = server_url
7878
self._devkey = devkey
7979
self._proxy = proxy
80+
self._setParams()
81+
82+
def _setParams(self):
8083
self._setParamsFromEnv()
81-
84+
8285
def _setParamsFromEnv(self):
8386
""" fill empty slots from environment variables
8487
_server_url <- TESTLINK_API_PYTHON_SERVER_URL

0 commit comments

Comments
 (0)