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 | |||
12 | from tcms.tests.factories import ComponentFactory |
||
13 | from tcms.tests.factories import TestExecutionFactory |
||
14 | |||
15 | |||
16 | @unittest.skipUnless(os.getenv('TEST_BUGTRACKER_INTEGRATION'), |
||
17 | 'Bug tracker integration testing not enabled') |
||
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(name='Redmine integration', |
||
33 | product=self.execution_1.run.plan.product) |
||
34 | self.execution_1.case.add_component(self.component) |
||
35 | |||
36 | bug_system = BugSystem.objects.create( # nosec:B106:hardcoded_password_funcarg |
||
37 | name='Redmine at kiwitcms.atlassian.net', |
||
38 | tracker_type='Redmine', |
||
39 | base_url='http://bugtracker.kiwitcms.org:3000', |
||
40 | api_username='admin', |
||
41 | api_password='admin', |
||
42 | ) |
||
43 | self.integration = Redmine(bug_system) |
||
44 | |||
45 | def test_bug_id_from_url(self): |
||
46 | result = self.integration.bug_id_from_url(self.existing_bug_url) |
||
47 | self.assertEqual(self.existing_bug_id, result) |
||
48 | |||
49 | def test_details_for_url(self): |
||
50 | result = self.integration.details(self.existing_bug_url) |
||
51 | |||
52 | self.assertEqual('Hello Redmine', result['title']) |
||
53 | self.assertEqual('Created via API', result['description']) |
||
54 | |||
55 | View Code Duplication | def test_auto_update_bugtracker(self): |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
56 | issue = self.integration.rpc.issue.get(self.existing_bug_id) |
||
57 | |||
58 | # make sure there are no comments to confuse the test |
||
59 | initial_comments_count = 0 |
||
60 | for comment in issue.journals: |
||
61 | initial_comments_count += 1 |
||
62 | self.assertNotIn(self.execution_1.run.summary, comment.notes) |
||
63 | |||
64 | # simulate user adding a new bug URL to a TE and clicking |
||
65 | # 'Automatically update bug tracker' |
||
66 | result = self.rpc_client.TestExecution.add_link({ |
||
67 | 'execution_id': self.execution_1.pk, |
||
68 | 'is_defect': True, |
||
69 | 'url': self.existing_bug_url, |
||
70 | }, True) |
||
71 | |||
72 | # making sure RPC above returned the same URL |
||
73 | self.assertEqual(self.existing_bug_url, result['url']) |
||
74 | |||
75 | # wait until comments have been refreshed b/c this seem to happen async |
||
76 | retries = 0 |
||
77 | current_comment_count = 0 |
||
78 | while current_comment_count <= initial_comments_count: |
||
79 | # fetch the issue again to refresh the journal |
||
80 | issue = self.integration.rpc.issue.get(self.existing_bug_id) |
||
81 | current_comment_count = len(issue.journals) |
||
82 | time.sleep(1) |
||
83 | retries += 1 |
||
84 | self.assertLess(retries, 20) |
||
85 | |||
86 | # this is an interator but is not a list |
||
87 | last_comment = None |
||
88 | for comment in issue.journals: |
||
89 | last_comment = comment |
||
90 | |||
91 | # assert that a comment has been added as the last one |
||
92 | # and also verify its text |
||
93 | for expected_string in [ |
||
94 | 'Confirmed via test execution', |
||
95 | "TR-%d: %s" % (self.execution_1.run_id, self.execution_1.run.summary), |
||
96 | self.execution_1.run.get_full_url(), |
||
97 | "TE-%d: %s" % (self.execution_1.pk, self.execution_1.case.summary)]: |
||
98 | self.assertIn(expected_string, last_comment.notes) |
||
99 | |||
100 | View Code Duplication | def test_report_issue_from_test_execution_1click_works(self): |
|
0 ignored issues
–
show
|
|||
101 | # simulate user clicking the 'Report bug' button in TE widget, TR page |
||
102 | result = self.rpc_client.Bug.report(self.execution_1.pk, self.integration.bug_system.pk) |
||
103 | self.assertEqual(result['rc'], 0) |
||
104 | self.assertIn(self.integration.bug_system.base_url, result['response']) |
||
105 | self.assertIn('http://bugtracker.kiwitcms.org:3000/issues/', result['response']) |
||
106 | |||
107 | new_issue_id = self.integration.bug_id_from_url(result['response']) |
||
108 | issue = self.integration.rpc.issue.get(new_issue_id) |
||
109 | |||
110 | self.assertEqual("Failed test: %s" % self.execution_1.case.summary, issue.subject) |
||
111 | for expected_string in [ |
||
112 | "Filed from execution %s" % self.execution_1.get_full_url(), |
||
113 | self.execution_1.run.plan.product.name, |
||
114 | self.component.name, |
||
115 | "Steps to reproduce", |
||
116 | self.execution_1.case.text]: |
||
117 | self.assertIn(expected_string, issue.description) |
||
118 | |||
119 | # verify that LR has been added to TE |
||
120 | self.assertTrue(LinkReference.objects.filter( |
||
121 | execution=self.execution_1, |
||
122 | url=result['response'], |
||
123 | is_defect=True, |
||
124 | ).exists()) |
||
125 |