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