1
|
|
|
# pylint: disable=attribute-defined-outside-init |
2
|
|
|
|
3
|
|
|
import os |
4
|
|
|
import time |
5
|
|
|
import unittest |
6
|
|
|
|
7
|
|
|
from tcms.core.contrib.linkreference.models import LinkReference |
8
|
|
|
from tcms.issuetracker.types import Redmine |
9
|
|
|
from tcms.rpc.tests.utils import APITestCase |
10
|
|
|
from tcms.testcases.models import BugSystem |
11
|
|
|
from tcms.tests.factories import ComponentFactory, TestExecutionFactory |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
@unittest.skipUnless( |
15
|
|
|
os.getenv("TEST_BUGTRACKER_INTEGRATION"), |
16
|
|
|
"Bug tracker integration testing not enabled", |
17
|
|
|
) |
18
|
|
|
class TestRedmineIntegration(APITestCase): |
19
|
|
|
existing_bug_id = 1 |
20
|
|
|
existing_bug_url = "http://bugtracker.kiwitcms.org:3000/issues/1" |
21
|
|
|
|
22
|
|
|
def _fixture_setup(self): |
23
|
|
|
super()._fixture_setup() |
24
|
|
|
|
25
|
|
|
self.execution_1 = TestExecutionFactory() |
26
|
|
|
self.execution_1.case.save() # will generate history object |
27
|
|
|
|
28
|
|
|
# this is the name of the Redmine Project |
29
|
|
|
self.execution_1.run.plan.product.name = "Integration with Kiwi TCMS" |
30
|
|
|
self.execution_1.run.plan.product.save() |
31
|
|
|
|
32
|
|
|
self.component = ComponentFactory( |
33
|
|
|
name="Redmine integration", product=self.execution_1.run.plan.product |
34
|
|
|
) |
35
|
|
|
self.execution_1.case.add_component(self.component) |
36
|
|
|
|
37
|
|
|
bug_system = BugSystem.objects.create( # nosec:B106:hardcoded_password_funcarg |
38
|
|
|
name="Redmine at kiwitcms.atlassian.net", |
39
|
|
|
tracker_type="tcms.issuetracker.types.Redmine", |
40
|
|
|
base_url="http://bugtracker.kiwitcms.org:3000", |
41
|
|
|
api_username="admin", |
42
|
|
|
api_password="admin", |
43
|
|
|
) |
44
|
|
|
self.integration = Redmine(bug_system, None) |
45
|
|
|
|
46
|
|
|
def test_bug_id_from_url(self): |
47
|
|
|
result = self.integration.bug_id_from_url(self.existing_bug_url) |
48
|
|
|
self.assertEqual(self.existing_bug_id, result) |
49
|
|
|
|
50
|
|
|
def test_details_for_url(self): |
51
|
|
|
result = self.integration.details(self.existing_bug_url) |
52
|
|
|
|
53
|
|
|
self.assertEqual("Hello Redmine", result["title"]) |
54
|
|
|
self.assertEqual("Created via API", result["description"]) |
55
|
|
|
|
56
|
|
View Code Duplication |
def test_auto_update_bugtracker(self): |
|
|
|
|
57
|
|
|
issue = self.integration.rpc.issue.get(self.existing_bug_id) |
58
|
|
|
|
59
|
|
|
# make sure there are no comments to confuse the test |
60
|
|
|
initial_comments_count = 0 |
61
|
|
|
for comment in issue.journals: |
62
|
|
|
initial_comments_count += 1 |
63
|
|
|
self.assertNotIn(self.execution_1.run.summary, comment.notes) |
64
|
|
|
|
65
|
|
|
# simulate user adding a new bug URL to a TE and clicking |
66
|
|
|
# 'Automatically update bug tracker' |
67
|
|
|
result = self.rpc_client.TestExecution.add_link( |
68
|
|
|
{ |
69
|
|
|
"execution_id": self.execution_1.pk, |
70
|
|
|
"is_defect": True, |
71
|
|
|
"url": self.existing_bug_url, |
72
|
|
|
}, |
73
|
|
|
True, |
74
|
|
|
) |
75
|
|
|
|
76
|
|
|
# making sure RPC above returned the same URL |
77
|
|
|
self.assertEqual(self.existing_bug_url, result["url"]) |
78
|
|
|
|
79
|
|
|
# wait until comments have been refreshed b/c this seem to happen async |
80
|
|
|
retries = 0 |
81
|
|
|
current_comment_count = 0 |
82
|
|
|
while current_comment_count <= initial_comments_count: |
83
|
|
|
# fetch the issue again to refresh the journal |
84
|
|
|
issue = self.integration.rpc.issue.get(self.existing_bug_id) |
85
|
|
|
current_comment_count = len(issue.journals) |
86
|
|
|
time.sleep(1) |
87
|
|
|
retries += 1 |
88
|
|
|
self.assertLess(retries, 20) |
89
|
|
|
|
90
|
|
|
# this is an interator but is not a list |
91
|
|
|
last_comment = None |
92
|
|
|
for comment in issue.journals: |
93
|
|
|
last_comment = comment |
94
|
|
|
|
95
|
|
|
# assert that a comment has been added as the last one |
96
|
|
|
# and also verify its text |
97
|
|
|
for expected_string in [ |
98
|
|
|
"Confirmed via test execution", |
99
|
|
|
f"TR-{self.execution_1.run_id}: {self.execution_1.run.summary}", |
100
|
|
|
self.execution_1.run.get_full_url(), |
101
|
|
|
f"TE-{self.execution_1.pk}: {self.execution_1.case.summary}", |
102
|
|
|
]: |
103
|
|
|
self.assertIn(expected_string, last_comment.notes) |
104
|
|
|
|
105
|
|
|
def test_report_issue_from_test_execution_1click_works(self): |
106
|
|
|
# simulate user clicking the 'Report bug' button in TE widget, TR page |
107
|
|
|
result = self.rpc_client.Bug.report( |
108
|
|
|
self.execution_1.pk, self.integration.bug_system.pk |
109
|
|
|
) |
110
|
|
|
self.assertEqual(result["rc"], 0) |
111
|
|
|
self.assertIn(self.integration.bug_system.base_url, result["response"]) |
112
|
|
|
self.assertIn("http://bugtracker.kiwitcms.org:3000/issues/", result["response"]) |
113
|
|
|
|
114
|
|
|
new_issue_id = self.integration.bug_id_from_url(result["response"]) |
115
|
|
|
issue = self.integration.rpc.issue.get(new_issue_id) |
116
|
|
|
|
117
|
|
|
self.assertEqual(f"Failed test: {self.execution_1.case.summary}", issue.subject) |
118
|
|
|
for expected_string in [ |
119
|
|
|
f"Filed from execution {self.execution_1.get_full_url()}", |
120
|
|
|
self.execution_1.run.plan.product.name, |
121
|
|
|
self.component.name, |
122
|
|
|
"Steps to reproduce", |
123
|
|
|
self.execution_1.case.text, |
124
|
|
|
]: |
125
|
|
|
self.assertIn(expected_string, issue.description) |
126
|
|
|
|
127
|
|
|
# verify that LR has been added to TE |
128
|
|
|
self.assertTrue( |
129
|
|
|
LinkReference.objects.filter( |
130
|
|
|
execution=self.execution_1, |
131
|
|
|
url=result["response"], |
132
|
|
|
is_defect=True, |
133
|
|
|
).exists() |
134
|
|
|
) |
135
|
|
|
|