1 | # -*- coding: utf-8 -*- |
||
2 | # pylint: disable=invalid-name, too-many-ancestors |
||
3 | |||
4 | from http import HTTPStatus |
||
5 | from django.urls import reverse |
||
6 | |||
7 | from tcms.testcases.models import BugSystem |
||
8 | |||
9 | from tcms.tests import BaseCaseRun |
||
10 | |||
11 | |||
12 | View Code Duplication | class Test_TestRunReportUnconfiguredJIRA(BaseCaseRun): |
|
0 ignored issues
–
show
Duplication
introduced
by
Loading history...
|
|||
13 | """ |
||
14 | When JIRA isn't fully configured, i.e. missing API URL |
||
15 | Username and Password/Token this leads to errors when |
||
16 | generating TR reports. See |
||
17 | https://github.com/kiwitcms/Kiwi/issues/100 |
||
18 | |||
19 | The problem is the underlying JIRA client assumes default |
||
20 | values and tries to connect to the JIRA instance upon |
||
21 | object creation! |
||
22 | """ |
||
23 | |||
24 | @classmethod |
||
25 | def setUpTestData(cls): |
||
26 | super(Test_TestRunReportUnconfiguredJIRA, cls).setUpTestData() |
||
27 | |||
28 | # NOTE: base_url, api_url, api_username and api_password |
||
29 | # are intentionally left blank! |
||
30 | cls.it = BugSystem.objects.create( |
||
31 | name='Partially configured JIRA', |
||
32 | url_reg_exp='https://jira.example.com/browse/%s', |
||
33 | validate_reg_exp=r'^[A-Z0-9]+-\d+$', |
||
34 | tracker_type='JIRA' |
||
35 | ) |
||
36 | |||
37 | cls.execution_1.add_bug('KIWI-1234', cls.it.pk) |
||
38 | |||
39 | def test_reports(self): |
||
40 | url = reverse('run-report', args=[self.execution_1.run_id]) |
||
41 | response = self.client.get(url) |
||
42 | |||
43 | self.assertEqual(HTTPStatus.OK, response.status_code) |
||
44 | self.assertContains(response, self.it.url_reg_exp % 'KIWI-1234') |
||
45 | |||
46 | |||
47 | View Code Duplication | class Test_TestRunReportUnconfiguredBugzilla(BaseCaseRun): |
|
0 ignored issues
–
show
|
|||
48 | """ |
||
49 | Test for https://github.com/kiwitcms/Kiwi/issues/100 |
||
50 | """ |
||
51 | |||
52 | @classmethod |
||
53 | def setUpTestData(cls): |
||
54 | super(Test_TestRunReportUnconfiguredBugzilla, cls).setUpTestData() |
||
55 | |||
56 | # NOTE: base_url, api_url, api_username and api_password |
||
57 | # are intentionally left blank! |
||
58 | cls.it = BugSystem.objects.create( |
||
59 | name='Partially configured Bugzilla', |
||
60 | url_reg_exp='https://bugzilla.example.com/show_bug.cgi?id=%s', |
||
61 | validate_reg_exp=r'^\d{1,7}$', |
||
62 | tracker_type='Bugzilla' |
||
63 | ) |
||
64 | |||
65 | cls.execution_1.add_bug('5678', cls.it.pk) |
||
66 | |||
67 | def test_reports(self): |
||
68 | url = reverse('run-report', args=[self.execution_1.run_id]) |
||
69 | response = self.client.get(url) |
||
70 | |||
71 | self.assertEqual(HTTPStatus.OK, response.status_code) |
||
72 | self.assertContains(response, self.it.url_reg_exp % '5678') |
||
73 | |||
74 | |||
75 | class Test_TestRunReportConfiguredBugzilla(BaseCaseRun): |
||
76 | """ |
||
77 | The report should not crash when loaded b/c the internal |
||
78 | bugzilla code will not try to establish and RPC connection |
||
79 | in the constructor. |
||
80 | """ |
||
81 | |||
82 | @classmethod |
||
83 | def setUpTestData(cls): |
||
84 | super().setUpTestData() |
||
85 | |||
86 | cls.it = BugSystem.objects.create( # nosec:B105:hardcoded_password_string |
||
87 | name='Partially configured Bugzilla', |
||
88 | url_reg_exp='https://bugzilla.example.com/show_bug.cgi?id=%s', |
||
89 | validate_reg_exp=r'^\d{1,7}$', |
||
90 | tracker_type='Bugzilla', |
||
91 | base_url='https://bugzilla.example.com', |
||
92 | api_url='https://bugzilla.example.com/xml-rpc/', |
||
93 | api_username='admin', |
||
94 | api_password='secret', |
||
95 | ) |
||
96 | |||
97 | cls.execution_1.add_bug('5678', cls.it.pk) |
||
98 | |||
99 | def test_reports(self): |
||
100 | url = reverse('run-report', args=[self.execution_1.run_id]) |
||
101 | response = self.client.get(url) |
||
102 | |||
103 | self.assertEqual(HTTPStatus.OK, response.status_code) |
||
104 | self.assertContains(response, self.it.url_reg_exp % '5678') |
||
105 | |||
106 | |||
107 | View Code Duplication | class Test_TestRunReportUnconfiguredGitHub(BaseCaseRun): |
|
0 ignored issues
–
show
|
|||
108 | """ |
||
109 | Test for https://github.com/kiwitcms/Kiwi/issues/100 |
||
110 | """ |
||
111 | |||
112 | @classmethod |
||
113 | def setUpTestData(cls): |
||
114 | super(Test_TestRunReportUnconfiguredGitHub, cls).setUpTestData() |
||
115 | |||
116 | # NOTE: base_url, api_url, api_username and api_password |
||
117 | # are intentionally left blank! |
||
118 | cls.it = BugSystem.objects.create( |
||
119 | name='Partially configured GitHub', |
||
120 | url_reg_exp='https://github.com/kiwitcms/Kiwi/issues/%s', |
||
121 | validate_reg_exp=r'^\d+$', |
||
122 | tracker_type='GitHub' |
||
123 | ) |
||
124 | |||
125 | cls.execution_1.add_bug('100', cls.it.pk) |
||
126 | |||
127 | def test_reports(self): |
||
128 | url = reverse('run-report', args=[self.execution_1.run_id]) |
||
129 | response = self.client.get(url) |
||
130 | |||
131 | self.assertEqual(HTTPStatus.OK, response.status_code) |
||
132 | self.assertContains(response, self.it.url_reg_exp % '100') |
||
133 |