1
|
|
|
# Copyright (c) 2019 Alexander Todorov <[email protected]> |
2
|
|
|
|
3
|
|
|
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
4
|
|
|
|
5
|
|
|
""" |
6
|
|
|
This module implements integration with Kiwi TCMS own bug tracking system! |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
from django.template.loader import render_to_string |
10
|
|
|
|
11
|
|
|
from tcms.bugs.views import New |
12
|
|
|
from tcms.bugs.models import Bug |
13
|
|
|
from tcms.issuetracker.base import IssueTrackerType |
14
|
|
|
from tcms.core.contrib.linkreference.models import LinkReference |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class KiwiTCMS(IssueTrackerType): |
18
|
|
|
""" |
19
|
|
|
Support for Kiwi TCMS. Required fields: |
20
|
|
|
|
21
|
|
|
:base_url: the FQDN of the current instance. Used to match against defect URLs. |
22
|
|
|
|
23
|
|
|
The rest of the fields are not used! |
24
|
|
|
""" |
25
|
|
|
|
26
|
|
|
def _rpc_connection(self): |
27
|
|
|
return None |
28
|
|
|
|
29
|
|
|
def is_adding_testcase_to_issue_disabled(self): # pylint: disable=invalid-name, no-self-use |
30
|
|
|
return False |
31
|
|
|
|
32
|
|
|
def details(self, url): |
33
|
|
|
""" |
34
|
|
|
Provide more details from our own bug tracker! |
35
|
|
|
""" |
36
|
|
|
bug_id = self.bug_id_from_url(url) |
37
|
|
|
bug = Bug.objects.get(pk=bug_id) |
38
|
|
|
|
39
|
|
|
result = { |
40
|
|
|
'title': bug.summary, |
41
|
|
|
'description': render_to_string('include/bug_details.html', |
42
|
|
|
{'object': bug}) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return result |
46
|
|
|
|
47
|
|
|
def add_testexecution_to_issue(self, executions, issue_url): |
48
|
|
|
""" |
49
|
|
|
Directly 'link' BUG and TE objects via their m2m |
50
|
|
|
relationship. |
51
|
|
|
|
52
|
|
|
.. note:: |
53
|
|
|
|
54
|
|
|
This method takes extra steps to safeguard from |
55
|
|
|
bogus input b/c it is called unconditionally from |
56
|
|
|
API method ``TestCase.add_link()``! |
57
|
|
|
""" |
58
|
|
|
try: |
59
|
|
|
bug_id = self.bug_id_from_url(issue_url) |
60
|
|
|
except AttributeError: |
61
|
|
|
return |
62
|
|
|
|
63
|
|
|
try: |
64
|
|
|
bug = Bug.objects.get(pk=bug_id) |
65
|
|
|
except Bug.DoesNotExist: |
66
|
|
|
return |
67
|
|
|
|
68
|
|
|
for execution in executions: |
69
|
|
|
bug.executions.add(execution) |
70
|
|
|
|
71
|
|
|
def report_issue_from_testexecution(self, execution, user): |
72
|
|
|
""" |
73
|
|
|
Create the new bug using internal API instead of |
74
|
|
|
going through the RPC layer and return its URL |
75
|
|
|
""" |
76
|
|
|
data = { |
77
|
|
|
'reporter': user, |
78
|
|
|
'summary': 'Test case failure: %s' % execution.case.summary, |
79
|
|
|
'product': execution.run.plan.product, |
80
|
|
|
'version': execution.run.product_version, |
81
|
|
|
'build': execution.build, |
82
|
|
|
'text': self._report_comment(execution), |
83
|
|
|
'_execution': execution, |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
bug = New.create_bug(data) |
87
|
|
|
|
88
|
|
|
# link Bug to TE via m2m |
89
|
|
|
bug.executions.add(execution) |
90
|
|
|
|
91
|
|
|
# and also add a link reference that will be shown in the UI |
92
|
|
|
LinkReference.objects.get_or_create( |
93
|
|
|
execution=execution, |
94
|
|
|
url=bug.get_full_url(), |
95
|
|
|
is_defect=True, |
96
|
|
|
) |
97
|
|
|
|
98
|
|
|
return bug.get_full_url() |
99
|
|
|
|
100
|
|
|
@classmethod |
101
|
|
|
def bug_id_from_url(cls, url): |
102
|
|
|
""" |
103
|
|
|
Strips the last '/' and returns the PK |
104
|
|
|
""" |
105
|
|
|
return super().bug_id_from_url(url.strip('/')) |
106
|
|
|
|