Skip to content

Commit

Permalink
Merge c2eeb96 into 48e5157
Browse files Browse the repository at this point in the history
  • Loading branch information
atodorov committed Apr 10, 2019
2 parents 48e5157 + c2eeb96 commit 894d9ca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
45 changes: 24 additions & 21 deletions tcms_api/plugin_helpers.py
Expand Up @@ -22,11 +22,11 @@ class Backend: # pylint: disable=too-many-instance-attributes
test_case_id = backend.test_case_get_or_create(<description>)
backend.add_test_case_to_plan(test_case_id, backend.plan_id)
test_case_run_id = backend.add_test_case_to_run(test_case_id,
backend.run_id)
backend.update_test_case_run(test_case_run_id,
<status_id>,
<comment>)
test_execution_id = backend.add_test_case_to_run(test_case_id,
backend.run_id)
backend.update_test_execution(test_execution_id,
<status_id>,
<comment>)
:param prefix: Prefix which will be added to TestPlan.name and
TestRun.summary
Expand Down Expand Up @@ -87,7 +87,7 @@ def configure(self):

def get_status_id(self, name):
"""
Get the PK of ``tcms.testruns.models.TestCaseRunStatus``
Get the PK of ``tcms.testruns.models.TestExecutionStatus``
matching the test execution status.
.. important::
Expand All @@ -96,12 +96,12 @@ def get_status_id(self, name):
id = backend.get_status_id('FAILED')
:param name: ``tcms.testruns.models.TestCaseRunStatus`` name
:param name: ``tcms.testruns.models.TestExecutionStatus`` name
:type name: str
:rtype: int
"""
if name not in self._statuses:
self._statuses[name] = self.rpc.TestCaseRunStatus.filter({
self._statuses[name] = self.rpc.TestExecutionStatus.filter({
'name': name
})[0]['id']

Expand Down Expand Up @@ -408,48 +408,51 @@ def add_test_case_to_run(self, case_id, run_id):
:type case_id: int
:param run_id: ``tcms.testruns.models.TestRun`` PK
:type run_id: int
:return: ``tcms.testruns.models.TestCaseRun`` PK
:return: ``tcms.testruns.models.TestExecution`` PK
:rtype: int
"""
if case_id in self._cases_in_test_run.keys():
return self._cases_in_test_run[case_id]

return self.rpc.TestRun.add_case(run_id, case_id)['case_run_id']

def update_test_case_run(self, test_case_run_id, status_id, comment=None):
def update_test_execution(self,
test_execution_id,
status_id,
comment=None):
"""
Update TestCaseRun with a status and comment.
Update TestExecution with a status and comment.
.. important::
Test runner plugins **must** call this method!
:param test_case_run_id: ``tcms.testruns.models.TestCaseRun`` PK
:type test_case_run_id: int
:param status_id: ``tcms.testruns.models.TestCaseRunStatus`` PK,
:param test_execution_id: ``tcms.testruns.models.TestExecution`` PK
:type test_execution_id: int
:param status_id: ``tcms.testruns.models.TestExecutionStatus`` PK,
for example the ID for PASSED, FAILED, etc.
:type status_id: int
:param comment: the string to add as a comment, defaults to None
:type comment: str
:return: None
"""
self.rpc.TestCaseRun.update(test_case_run_id, {'status': status_id})
self.rpc.TestExecution.update(test_execution_id, {'status': status_id})

if comment:
self.add_comment(test_case_run_id, comment)
self.add_comment(test_execution_id, comment)

def add_comment(self, test_case_run_id, comment):
def add_comment(self, test_execution_id, comment):
"""
Add comment string to TestCaseRun without changing the status
Add comment string to TestExecution without changing the status
.. important::
Test runner plugins **must** call this method!
:param test_case_run_id: ``tcms.testruns.models.TestCaseRun`` PK
:type test_case_run_id: int
:param test_execution_id: ``tcms.testruns.models.TestExecution`` PK
:type test_execution_id: int
:param comment: the string to add as a comment
:type comment: str
:return: None
"""
self.rpc.TestCaseRun.add_comment(test_case_run_id, comment)
self.rpc.TestExecution.add_comment(test_execution_id, comment)
6 changes: 3 additions & 3 deletions tests/test_status.py
Expand Up @@ -11,14 +11,14 @@ def setUpClass(cls):
super().setUpClass()
cls.backend._statuses = {'PASSED': 1}
cls.backend.rpc = MagicMock()
cls.backend.rpc.TestCaseRunStatus.filter = MagicMock()
cls.backend.rpc.TestExecutionStatus.filter = MagicMock()

def test_when_status_in_cache_then_return_from_cache(self):
self.backend.get_status_id('PASSED')
self.backend.rpc.TestCaseRunStatus.filter.assert_not_called()
self.backend.rpc.TestExecutionStatus.filter.assert_not_called()

def test_when_status_not_in_cache_then_return_from_cache(self):
self.backend.get_status_id('FAILED')
self.backend.rpc.TestCaseRunStatus.filter.assert_called_with({
self.backend.rpc.TestExecutionStatus.filter.assert_called_with({
'name': 'FAILED',
})

0 comments on commit 894d9ca

Please sign in to comment.