|
| 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() |
0 commit comments