1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# pylint: disable=invalid-name, attribute-defined-outside-init, objects-update-used |
3
|
|
|
|
4
|
|
|
from datetime import datetime |
5
|
|
|
|
6
|
|
|
from xmlrpc.client import ProtocolError |
7
|
|
|
from xmlrpc.client import Fault as XmlRPCFault |
8
|
|
|
|
9
|
|
|
from django.test import override_settings |
10
|
|
|
|
11
|
|
|
from tcms.core.contrib.linkreference.models import LinkReference |
12
|
|
|
from tcms.testruns.models import TestExecutionStatus |
13
|
|
|
|
14
|
|
|
from tcms.tests.factories import ProductFactory |
15
|
|
|
from tcms.tests.factories import TestCaseFactory |
16
|
|
|
from tcms.tests.factories import TestExecutionFactory |
17
|
|
|
from tcms.tests.factories import TestPlanFactory |
18
|
|
|
from tcms.tests.factories import TestRunFactory |
19
|
|
|
from tcms.tests.factories import UserFactory |
20
|
|
|
from tcms.tests.factories import VersionFactory |
21
|
|
|
from tcms.tests.factories import BuildFactory |
22
|
|
|
from tcms.rpc.tests.utils import XmlrpcAPIBaseTest |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
@override_settings(LANGUAGE_CODE='en-us') |
26
|
|
|
class TestExecutionCreate(XmlrpcAPIBaseTest): # pylint: disable=too-many-instance-attributes |
27
|
|
|
"""Test TestExecution.create""" |
28
|
|
|
|
29
|
|
|
def _fixture_setup(self): |
30
|
|
|
super()._fixture_setup() |
31
|
|
|
|
32
|
|
|
self.staff = UserFactory(username='staff', email='[email protected]') |
33
|
|
|
|
34
|
|
|
self.product = ProductFactory(name='Nitrate') |
35
|
|
|
self.version = VersionFactory(value='0.1', product=self.product) |
36
|
|
|
self.build = self.product.build.first() |
37
|
|
|
self.plan = TestPlanFactory(author=self.api_user, product=self.product) |
38
|
|
|
self.test_run = TestRunFactory(product_version=self.version, build=self.build, |
39
|
|
|
default_tester=None, plan=self.plan) |
40
|
|
|
self.status = TestExecutionStatus.objects.get(name='IDLE') |
41
|
|
|
self.case = TestCaseFactory(author=self.api_user, default_tester=None, plan=[self.plan]) |
42
|
|
|
|
43
|
|
|
self.execution_pks = [] |
44
|
|
|
|
45
|
|
|
def test_create_with_no_required_fields(self): |
46
|
|
|
values = [ |
47
|
|
|
{ |
48
|
|
|
"assignee": self.staff.pk, |
49
|
|
|
"status": self.status.pk, |
50
|
|
|
}, |
51
|
|
|
{ |
52
|
|
|
"build": self.build.pk, |
53
|
|
|
"assignee": self.staff.pk, |
54
|
|
|
"status": 1, |
55
|
|
|
}, |
56
|
|
|
{ |
57
|
|
|
"run": self.test_run.pk, |
58
|
|
|
"build": self.build.pk, |
59
|
|
|
"assignee": self.staff.pk, |
60
|
|
|
"status": self.status.pk, |
61
|
|
|
}, |
62
|
|
|
] |
63
|
|
|
for value in values: |
64
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'This field is required'): |
65
|
|
|
self.rpc_client.exec.TestExecution.create(value) |
66
|
|
|
|
67
|
|
|
def test_create_with_required_fields(self): |
68
|
|
|
tcr = self.rpc_client.exec.TestExecution.create({ |
69
|
|
|
"run": self.test_run.pk, |
70
|
|
|
"build": self.build.pk, |
71
|
|
|
"case": self.case.pk, |
72
|
|
|
"case_text_version": 15, |
73
|
|
|
}) |
74
|
|
|
self.assertIsNotNone(tcr) |
75
|
|
|
self.execution_pks.append(tcr['case_run_id']) |
76
|
|
|
self.assertEqual(tcr['build_id'], self.build.pk) |
77
|
|
|
self.assertEqual(tcr['case_id'], self.case.pk) |
78
|
|
|
self.assertEqual(tcr['run_id'], self.test_run.pk) |
79
|
|
|
|
80
|
|
|
def test_create_with_all_fields(self): |
81
|
|
|
tcr = self.rpc_client.exec.TestExecution.create({ |
82
|
|
|
"run": self.test_run.pk, |
83
|
|
|
"build": self.build.pk, |
84
|
|
|
"case": self.case.pk, |
85
|
|
|
"assignee": self.api_user.pk, |
86
|
|
|
"sortkey": 90, |
87
|
|
|
"status": self.status.pk, |
88
|
|
|
"case_text_version": 3, |
89
|
|
|
}) |
90
|
|
|
self.assertIsNotNone(tcr) |
91
|
|
|
self.execution_pks.append(tcr['case_run_id']) |
92
|
|
|
self.assertEqual(tcr['build_id'], self.build.pk) |
93
|
|
|
self.assertEqual(tcr['case_id'], self.case.pk) |
94
|
|
|
self.assertEqual(tcr['assignee_id'], self.api_user.pk) |
95
|
|
|
self.assertEqual(tcr['sortkey'], 90) |
96
|
|
|
self.assertEqual(tcr['status'], 'IDLE') |
97
|
|
|
self.assertEqual(tcr['case_text_version'], 3) |
98
|
|
|
|
99
|
|
|
def test_create_with_non_exist_fields(self): |
100
|
|
|
values = [ |
101
|
|
|
{ |
102
|
|
|
"run": self.test_run.pk, |
103
|
|
|
"build": self.build.pk, |
104
|
|
|
"case": 111111, |
105
|
|
|
}, |
106
|
|
|
{ |
107
|
|
|
"run": 11111, |
108
|
|
|
"build": self.build.pk, |
109
|
|
|
"case": self.case.pk, |
110
|
|
|
}, |
111
|
|
|
{ |
112
|
|
|
"run": self.test_run.pk, |
113
|
|
|
"build": 11222222, |
114
|
|
|
"case": self.case.pk, |
115
|
|
|
}, |
116
|
|
|
] |
117
|
|
|
for value in values: |
118
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'): |
119
|
|
|
self.rpc_client.exec.TestExecution.create(value) |
120
|
|
|
|
121
|
|
|
def test_create_with_no_perm(self): |
122
|
|
|
values = { |
123
|
|
|
"run": self.test_run.pk, |
124
|
|
|
"build": self.build.pk, |
125
|
|
|
"case": self.case.pk, |
126
|
|
|
"assignee": self.api_user.pk, |
127
|
|
|
"sortkey": 2, |
128
|
|
|
"status": self.status.pk, |
129
|
|
|
} |
130
|
|
|
self.rpc_client.exec.Auth.logout() |
131
|
|
|
with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): |
132
|
|
|
self.rpc_client.exec.TestExecution.create(values) |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
class TestExecutionAddComment(XmlrpcAPIBaseTest): |
136
|
|
|
"""Test TestExecution.add_comment""" |
137
|
|
|
|
138
|
|
|
def _fixture_setup(self): |
139
|
|
|
super(TestExecutionAddComment, self)._fixture_setup() |
140
|
|
|
|
141
|
|
|
self.case_run_1 = TestExecutionFactory() |
142
|
|
|
self.case_run_2 = TestExecutionFactory() |
143
|
|
|
|
144
|
|
|
def test_add_comment_with_int(self): |
145
|
|
|
comment = self.rpc_client.exec.TestExecution.add_comment(self.case_run_2.pk, "Hello World!") |
146
|
|
|
self.assertIsNone(comment) |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
@override_settings(LANGUAGE_CODE='en-us') |
150
|
|
|
class TestExecutionAddLink(XmlrpcAPIBaseTest): |
151
|
|
|
"""Test TestExecution.add_link""" |
152
|
|
|
|
153
|
|
|
def _fixture_setup(self): |
154
|
|
|
super()._fixture_setup() |
155
|
|
|
|
156
|
|
|
self.case_run = TestExecutionFactory() |
157
|
|
|
|
158
|
|
|
def test_attach_log_with_non_existing_id(self): |
159
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'constraint fail|violates foreign key'): |
160
|
|
|
self.rpc_client.exec.TestExecution.add_link({ |
161
|
|
|
'execution_id': -5, |
162
|
|
|
'name': 'A test log', |
163
|
|
|
'url': 'http://example.com'}) |
164
|
|
|
|
165
|
|
|
def test_attach_log(self): |
166
|
|
|
url = "http://127.0.0.1/test/test-log.log" |
167
|
|
|
result = self.rpc_client.exec.TestExecution.add_link({ |
168
|
|
|
'execution_id': self.case_run.pk, |
169
|
|
|
'name': 'UT test logs', |
170
|
|
|
'url': url}) |
171
|
|
|
self.assertGreater(result['id'], 0) |
172
|
|
|
self.assertEqual(result['url'], url) |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
class TestExecutionRemoveLink(XmlrpcAPIBaseTest): |
176
|
|
|
|
177
|
|
|
def _fixture_setup(self): |
178
|
|
|
super()._fixture_setup() |
179
|
|
|
|
180
|
|
|
self.status_idle = TestExecutionStatus.objects.get(name='IDLE') |
181
|
|
|
self.tester = UserFactory() |
182
|
|
|
self.case_run = TestExecutionFactory(assignee=self.tester, tested_by=None, |
183
|
|
|
sortkey=10, |
184
|
|
|
status=self.status_idle) |
185
|
|
|
|
186
|
|
|
def setUp(self): |
187
|
|
|
super().setUp() |
188
|
|
|
|
189
|
|
|
self.rpc_client.exec.TestExecution.add_link({ |
190
|
|
|
'execution_id': self.case_run.pk, |
191
|
|
|
'name': 'Related issue', |
192
|
|
|
'url': 'https://localhost/issue/1'}) |
193
|
|
|
self.link = self.case_run.links()[0] |
194
|
|
|
|
195
|
|
|
def test_doesnt_raise_with_non_existing_id(self): |
196
|
|
|
self.rpc_client.exec.TestExecution.remove_link({'execution_id': -9}) |
197
|
|
|
links = self.case_run.links() |
198
|
|
|
self.assertEqual(1, links.count()) |
199
|
|
|
self.assertEqual(self.link.pk, links[0].pk) |
200
|
|
|
|
201
|
|
|
def test_detach_log_with_non_exist_log(self): |
202
|
|
|
self.rpc_client.exec.TestExecution.remove_link({'pk': 999999999}) |
203
|
|
|
links = self.case_run.links() |
204
|
|
|
self.assertEqual(1, links.count()) |
205
|
|
|
self.assertEqual(self.link.pk, links[0].pk) |
206
|
|
|
|
207
|
|
|
def test_detach_log(self): |
208
|
|
|
self.rpc_client.exec.TestExecution.remove_link({'execution_id': self.case_run.pk, |
209
|
|
|
'pk': self.link.pk}) |
210
|
|
|
self.assertEqual([], list(self.case_run.links())) |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
class TestExecutionFilter(XmlrpcAPIBaseTest): |
214
|
|
|
|
215
|
|
|
def _fixture_setup(self): |
216
|
|
|
super()._fixture_setup() |
217
|
|
|
|
218
|
|
|
self.status_idle = TestExecutionStatus.objects.get(name='IDLE') |
219
|
|
|
self.tester = UserFactory() |
220
|
|
|
self.case_run = TestExecutionFactory(assignee=self.tester, tested_by=None, |
221
|
|
|
sortkey=10, |
222
|
|
|
status=self.status_idle) |
223
|
|
|
|
224
|
|
|
def test_with_non_exist_id(self): |
225
|
|
|
found = self.rpc_client.exec.TestExecution.filter({'pk': -1}) |
226
|
|
|
self.assertEqual(0, len(found)) |
227
|
|
|
|
228
|
|
|
def test_filter_by_id(self): |
229
|
|
|
tcr = self.rpc_client.exec.TestExecution.filter({'pk': self.case_run.pk})[0] |
230
|
|
|
self.assertIsNotNone(tcr) |
231
|
|
|
self.assertEqual(tcr['build_id'], self.case_run.build.pk) |
232
|
|
|
self.assertEqual(tcr['case_id'], self.case_run.case.pk) |
233
|
|
|
self.assertEqual(tcr['assignee_id'], self.tester.pk) |
234
|
|
|
self.assertEqual(tcr['tested_by_id'], None) |
235
|
|
|
self.assertEqual(tcr['sortkey'], 10) |
236
|
|
|
self.assertEqual(tcr['status'], 'IDLE') |
237
|
|
|
self.assertEqual(tcr['status_id'], self.status_idle.pk) |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
class TestExecutionGetLinks(XmlrpcAPIBaseTest): |
241
|
|
|
|
242
|
|
|
def _fixture_setup(self): |
243
|
|
|
super()._fixture_setup() |
244
|
|
|
|
245
|
|
|
self.case_run_1 = TestExecutionFactory() |
246
|
|
|
self.case_run_2 = TestExecutionFactory() |
247
|
|
|
|
248
|
|
|
self.rpc_client.exec.TestExecution.add_link({ |
249
|
|
|
'execution_id': self.case_run_1.pk, |
250
|
|
|
'name': 'Test logs', |
251
|
|
|
'url': 'http://kiwitcms.org'}) |
252
|
|
|
|
253
|
|
|
def test_get_links_with_non_exist_id(self): |
254
|
|
|
result = self.rpc_client.exec.TestExecution.get_links({'execution': -9}) |
255
|
|
|
self.assertEqual([], result) |
256
|
|
|
|
257
|
|
|
def test_get_empty_logs(self): |
258
|
|
|
logs = self.rpc_client.exec.TestExecution.get_links({'execution': self.case_run_2.pk}) |
259
|
|
|
self.assertIsInstance(logs, list) |
260
|
|
|
self.assertEqual(len(logs), 0) |
261
|
|
|
|
262
|
|
|
def test_get_links(self): |
263
|
|
|
tcr_log = LinkReference.objects.get(execution=self.case_run_1.pk) |
264
|
|
|
logs = self.rpc_client.exec.TestExecution.get_links({'execution': self.case_run_1.pk}) |
265
|
|
|
self.assertIsInstance(logs, list) |
266
|
|
|
self.assertEqual(len(logs), 1) |
267
|
|
|
self.assertEqual(logs[0]['id'], tcr_log.pk) |
268
|
|
|
self.assertEqual(logs[0]['name'], "Test logs") |
269
|
|
|
self.assertEqual(logs[0]['url'], 'http://kiwitcms.org') |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
@override_settings(LANGUAGE_CODE='en-us') |
273
|
|
|
class TestExecutionUpdate(XmlrpcAPIBaseTest): |
274
|
|
|
|
275
|
|
|
def _fixture_setup(self): |
276
|
|
|
super()._fixture_setup() |
277
|
|
|
|
278
|
|
|
self.user = UserFactory() |
279
|
|
|
self.build = BuildFactory() |
280
|
|
|
self.case_run_1 = TestExecutionFactory() |
281
|
|
|
self.case_run_2 = TestExecutionFactory() |
282
|
|
|
self.status_running = TestExecutionStatus.objects.get(name='RUNNING') |
283
|
|
|
|
284
|
|
|
def test_update_with_single_caserun(self): |
285
|
|
|
tcr = self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, { |
286
|
|
|
"build": self.build.pk, |
287
|
|
|
"assignee": self.user.pk, |
288
|
|
|
"status": self.status_running.pk, |
289
|
|
|
"sortkey": 90 |
290
|
|
|
}) |
291
|
|
|
self.assertEqual(tcr['build'], self.build.name) |
292
|
|
|
self.assertEqual(tcr['assignee'], self.user.username) |
293
|
|
|
self.assertEqual(tcr['status'], 'RUNNING') |
294
|
|
|
self.assertEqual(tcr['sortkey'], 90) |
295
|
|
|
|
296
|
|
|
def test_update_with_non_existing_build(self): |
297
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'): |
298
|
|
|
self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, {"build": 1111111}) |
299
|
|
|
|
300
|
|
|
def test_update_with_non_existing_assignee(self): |
301
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'): |
302
|
|
|
self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, {"assignee": 1111111}) |
303
|
|
|
|
304
|
|
|
def test_update_with_non_existing_status(self): |
305
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Select a valid choice'): |
306
|
|
|
self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, |
307
|
|
|
{"status": 1111111}) |
308
|
|
|
|
309
|
|
|
def test_update_with_no_perm(self): |
310
|
|
|
self.rpc_client.exec.Auth.logout() |
311
|
|
|
with self.assertRaisesRegex(ProtocolError, '403 Forbidden'): |
312
|
|
|
self.rpc_client.exec.TestExecution.update(self.case_run_1.pk, |
313
|
|
|
{"close_date": datetime.now()}) |
314
|
|
|
|