1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# pylint: disable=attribute-defined-outside-init, objects-update-used |
3
|
|
|
from datetime import datetime |
4
|
|
|
from xmlrpc.client import Fault as XmlRPCFault |
5
|
|
|
from xmlrpc.client import ProtocolError |
6
|
|
|
|
7
|
|
|
from django.contrib.auth.models import Permission |
8
|
|
|
from django.utils.translation import gettext_lazy as _ |
9
|
|
|
from tcms_api import xmlrpc |
10
|
|
|
|
11
|
|
|
from tcms.rpc.tests.utils import APIPermissionsTestCase, APITestCase |
12
|
|
|
from tcms.testcases.models import TestCaseStatus |
13
|
|
|
from tcms.testruns.models import TestExecution, TestRun |
14
|
|
|
from tcms.tests import remove_perm_from_user |
15
|
|
|
from tcms.tests.factories import ( |
16
|
|
|
BuildFactory, |
17
|
|
|
ProductFactory, |
18
|
|
|
TagFactory, |
19
|
|
|
TestCaseFactory, |
20
|
|
|
TestExecutionFactory, |
21
|
|
|
TestPlanFactory, |
22
|
|
|
TestRunFactory, |
23
|
|
|
UserFactory, |
24
|
|
|
VersionFactory, |
25
|
|
|
) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class TestAddCase(APITestCase): |
29
|
|
|
def _fixture_setup(self): |
30
|
|
|
super()._fixture_setup() |
31
|
|
|
|
32
|
|
|
self.plan = TestPlanFactory(author=self.api_user) |
33
|
|
|
|
34
|
|
|
self.test_case = TestCaseFactory() |
35
|
|
|
self.test_case.case_status = TestCaseStatus.objects.filter( |
36
|
|
|
is_confirmed=True |
37
|
|
|
).first() |
38
|
|
|
self.test_case.save() # generate history object |
39
|
|
|
self.plan.add_case(self.test_case) |
40
|
|
|
|
41
|
|
|
self.test_run = TestRunFactory(plan=self.plan) |
42
|
|
|
|
43
|
|
|
def test_add_case(self): |
44
|
|
|
result = self.rpc_client.TestRun.add_case(self.test_run.pk, self.test_case.pk) |
45
|
|
|
self.assertTrue(isinstance(result, dict)) |
46
|
|
|
|
47
|
|
|
execution = TestExecution.objects.get( |
48
|
|
|
run=self.test_run.pk, case=self.test_case.pk |
49
|
|
|
) |
50
|
|
|
|
51
|
|
|
self.assertEqual(result["id"], execution.pk) |
52
|
|
|
self.assertIn("assignee", result) |
53
|
|
|
self.assertEqual(result["tested_by"], None) |
54
|
|
|
self.assertIn("case_text_version", result) |
55
|
|
|
self.assertIn("start_date", result) |
56
|
|
|
self.assertIn("stop_date", result) |
57
|
|
|
self.assertIn("sortkey", result) |
58
|
|
|
self.assertEqual(result["run"], execution.run.pk) |
59
|
|
|
self.assertEqual(result["case"], execution.case.pk) |
60
|
|
|
self.assertIn("build", result) |
61
|
|
|
self.assertIn("status", result) |
62
|
|
|
|
63
|
|
|
def test_add_case_without_permissions(self): |
64
|
|
|
unauthorized_user = UserFactory() |
65
|
|
|
unauthorized_user.set_password("api-testing") |
66
|
|
|
unauthorized_user.save() |
67
|
|
|
|
68
|
|
|
unauthorized_user.user_permissions.add(*Permission.objects.all()) |
69
|
|
|
remove_perm_from_user(unauthorized_user, "testruns.add_testexecution") |
70
|
|
|
|
71
|
|
|
rpc_client = xmlrpc.TCMSXmlrpc( |
72
|
|
|
unauthorized_user.username, |
73
|
|
|
"api-testing", |
74
|
|
|
"%s/xml-rpc/" % self.live_server_url, |
75
|
|
|
).server |
76
|
|
|
|
77
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
78
|
|
|
rpc_client.TestRun.add_case(self.test_run.pk, self.test_case.pk) |
79
|
|
|
|
80
|
|
|
exists = TestExecution.objects.filter( |
81
|
|
|
run=self.test_run.pk, case=self.test_case.pk |
82
|
|
|
).exists() |
83
|
|
|
self.assertFalse(exists) |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
class TestRemovesCase(APITestCase): |
87
|
|
|
def _fixture_setup(self): |
88
|
|
|
super()._fixture_setup() |
89
|
|
|
|
90
|
|
|
self.plan = TestPlanFactory(author=self.api_user) |
91
|
|
|
|
92
|
|
|
self.test_case = TestCaseFactory() |
93
|
|
|
self.test_case.save() # generate history object |
94
|
|
|
self.plan.add_case(self.test_case) |
95
|
|
|
|
96
|
|
|
self.test_run = TestRunFactory(plan=self.plan) |
97
|
|
|
self.test_execution = TestExecutionFactory( |
98
|
|
|
run=self.test_run, case=self.test_case |
99
|
|
|
) |
100
|
|
|
self.test_execution.save() |
101
|
|
|
|
102
|
|
|
def test_nothing_change_if_invalid_case_passed(self): |
103
|
|
|
self.rpc_client.TestRun.remove_case(self.test_run.pk, 999999) |
104
|
|
|
self.test_execution.refresh_from_db() |
105
|
|
|
self.assertTrue( |
106
|
|
|
TestExecution.objects.filter(pk=self.test_execution.pk).exists() |
107
|
|
|
) |
108
|
|
|
self.assertEqual(1, TestExecution.objects.count()) |
109
|
|
|
|
110
|
|
|
def test_nothing_change_if_invalid_run_passed(self): |
111
|
|
|
self.rpc_client.TestRun.remove_case(99999, self.test_case.pk) |
112
|
|
|
self.test_execution.refresh_from_db() |
113
|
|
|
self.assertTrue( |
114
|
|
|
TestExecution.objects.filter(pk=self.test_execution.pk).exists() |
115
|
|
|
) |
116
|
|
|
self.assertEqual(1, TestExecution.objects.count()) |
117
|
|
|
|
118
|
|
|
def test_remove_case_without_permissions(self): |
119
|
|
|
unauthorized_user = UserFactory() |
120
|
|
|
unauthorized_user.set_password("api-testing") |
121
|
|
|
unauthorized_user.save() |
122
|
|
|
|
123
|
|
|
unauthorized_user.user_permissions.add(*Permission.objects.all()) |
124
|
|
|
remove_perm_from_user(unauthorized_user, "testruns.delete_testexecution") |
125
|
|
|
|
126
|
|
|
rpc_client = xmlrpc.TCMSXmlrpc( |
127
|
|
|
unauthorized_user.username, |
128
|
|
|
"api-testing", |
129
|
|
|
"%s/xml-rpc/" % self.live_server_url, |
130
|
|
|
).server |
131
|
|
|
|
132
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
133
|
|
|
rpc_client.TestRun.remove_case(self.test_run.pk, self.test_case.pk) |
134
|
|
|
|
135
|
|
|
exists = TestExecution.objects.filter( |
136
|
|
|
run=self.test_run.pk, case=self.test_case.pk |
137
|
|
|
).exists() |
138
|
|
|
self.assertTrue(exists) |
139
|
|
|
|
140
|
|
|
def test_should_remove_an_execution(self): |
141
|
|
|
self.rpc_client.TestRun.remove_case(self.test_run.pk, self.test_case.pk) |
142
|
|
|
self.assertFalse( |
143
|
|
|
TestExecution.objects.filter(pk=self.test_execution.pk).exists() |
144
|
|
|
) |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
class TestGetCases(APITestCase): |
148
|
|
|
def _fixture_setup(self): |
149
|
|
|
super()._fixture_setup() |
150
|
|
|
|
151
|
|
|
self.test_case = TestCaseFactory() |
152
|
|
|
self.test_case.case_status = TestCaseStatus.objects.filter( |
153
|
|
|
is_confirmed=True |
154
|
|
|
).first() |
155
|
|
|
self.test_case.save() |
156
|
|
|
self.test_run = TestRunFactory() |
157
|
|
|
|
158
|
|
|
def test_get_empty_result_if_no_case_added(self): |
159
|
|
|
result = self.rpc_client.TestRun.get_cases(self.test_run.pk) |
160
|
|
|
self.assertEqual(0, len(result)) |
161
|
|
|
|
162
|
|
|
def test_get_cases(self): |
163
|
|
|
self.test_run.create_execution(case=self.test_case) |
164
|
|
|
result = self.rpc_client.TestRun.get_cases(self.test_run.pk) |
165
|
|
|
self.assertEqual(1, len(result)) |
166
|
|
|
|
167
|
|
|
case = result[0] |
168
|
|
|
|
169
|
|
|
self.assertEqual(case["id"], self.test_case.pk) |
170
|
|
|
self.assertIn("execution_id", case) |
171
|
|
|
self.assertIn("status", case) |
172
|
|
|
|
173
|
|
|
self.assertIn("create_date", case) |
174
|
|
|
self.assertIn("is_automated", case) |
175
|
|
|
self.assertIn("script", case) |
176
|
|
|
self.assertIn("arguments", case) |
177
|
|
|
self.assertIn("extra_link", case) |
178
|
|
|
self.assertIn("summary", case) |
179
|
|
|
self.assertIn("requirement", case) |
180
|
|
|
self.assertIn("notes", case) |
181
|
|
|
self.assertIn("text", case) |
182
|
|
|
self.assertIn("case_status", case) |
183
|
|
|
self.assertIn("category", case) |
184
|
|
|
self.assertIn("priority", case) |
185
|
|
|
self.assertIn("author", case) |
186
|
|
|
self.assertIn("default_tester", case) |
187
|
|
|
self.assertIn("reviewer", case) |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
class TestGetCasesPermission(APIPermissionsTestCase): |
191
|
|
|
permission_label = "testruns.view_testrun" |
192
|
|
|
|
193
|
|
|
def _fixture_setup(self): |
194
|
|
|
super()._fixture_setup() |
195
|
|
|
|
196
|
|
|
self.test_run = TestRunFactory() |
197
|
|
|
|
198
|
|
|
def verify_api_with_permission(self): |
199
|
|
|
result = self.rpc_client.TestRun.get_cases(self.test_run.pk) |
200
|
|
|
self.assertTrue(isinstance(result, list)) |
201
|
|
|
|
202
|
|
|
def verify_api_without_permission(self): |
203
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
204
|
|
|
self.rpc_client.TestRun.get_cases(self.test_run.pk) |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
class TestAddTag(APITestCase): |
208
|
|
|
def _fixture_setup(self): |
209
|
|
|
super()._fixture_setup() |
210
|
|
|
|
211
|
|
|
self.plan = TestPlanFactory(author=self.api_user) |
212
|
|
|
self.build = BuildFactory(version=self.plan.product_version) |
213
|
|
|
|
214
|
|
|
self.test_runs = [ |
215
|
|
|
TestRunFactory( |
216
|
|
|
build=self.build, |
217
|
|
|
default_tester=None, |
218
|
|
|
plan=self.plan, |
219
|
|
|
), |
220
|
|
|
TestRunFactory( |
221
|
|
|
build=self.build, |
222
|
|
|
default_tester=None, |
223
|
|
|
plan=self.plan, |
224
|
|
|
), |
225
|
|
|
] |
226
|
|
|
|
227
|
|
|
self.tag0 = TagFactory(name="xmlrpc_test_tag_0") |
228
|
|
|
self.tag1 = TagFactory(name="xmlrpc_test_tag_1") |
229
|
|
|
|
230
|
|
|
def test_add_tag(self): |
231
|
|
|
result = self.rpc_client.TestRun.add_tag(self.test_runs[0].pk, self.tag0.name) |
232
|
|
|
self.assertEqual(len(result), 1) |
233
|
|
|
self.assertEqual(result[0]["id"], self.tag0.pk) |
234
|
|
|
self.assertEqual(result[0]["name"], self.tag0.name) |
235
|
|
|
|
236
|
|
|
tag_exists = TestRun.objects.filter( |
237
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag0.pk |
238
|
|
|
).exists() |
239
|
|
|
self.assertTrue(tag_exists) |
240
|
|
|
|
241
|
|
|
def test_add_tag_without_permissions(self): |
242
|
|
|
unauthorized_user = UserFactory() |
243
|
|
|
unauthorized_user.set_password("api-testing") |
244
|
|
|
unauthorized_user.save() |
245
|
|
|
|
246
|
|
|
unauthorized_user.user_permissions.add(*Permission.objects.all()) |
247
|
|
|
remove_perm_from_user(unauthorized_user, "testruns.add_testruntag") |
248
|
|
|
|
249
|
|
|
rpc_client = xmlrpc.TCMSXmlrpc( |
250
|
|
|
unauthorized_user.username, |
251
|
|
|
"api-testing", |
252
|
|
|
"%s/xml-rpc/" % self.live_server_url, |
253
|
|
|
).server |
254
|
|
|
|
255
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
256
|
|
|
rpc_client.TestRun.add_tag(self.test_runs[0].pk, self.tag0.name) |
257
|
|
|
|
258
|
|
|
# tags were not modified |
259
|
|
|
tag_exists = TestRun.objects.filter( |
260
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag0.pk |
261
|
|
|
).exists() |
262
|
|
|
self.assertFalse(tag_exists) |
263
|
|
|
|
264
|
|
|
|
265
|
|
|
class TestRemoveTag(APITestCase): |
266
|
|
|
def _fixture_setup(self): |
267
|
|
|
super()._fixture_setup() |
268
|
|
|
|
269
|
|
|
self.product = ProductFactory() |
270
|
|
|
self.version = VersionFactory(product=self.product) |
271
|
|
|
self.build = BuildFactory(version=self.version) |
272
|
|
|
self.plan = TestPlanFactory(author=self.api_user, product=self.product) |
273
|
|
|
|
274
|
|
|
self.test_runs = [ |
275
|
|
|
TestRunFactory( |
276
|
|
|
build=self.build, |
277
|
|
|
default_tester=None, |
278
|
|
|
plan=self.plan, |
279
|
|
|
), |
280
|
|
|
TestRunFactory( |
281
|
|
|
build=self.build, |
282
|
|
|
default_tester=None, |
283
|
|
|
plan=self.plan, |
284
|
|
|
), |
285
|
|
|
] |
286
|
|
|
|
287
|
|
|
self.tag0 = TagFactory(name="xmlrpc_test_tag_0") |
288
|
|
|
self.tag1 = TagFactory(name="xmlrpc_test_tag_1") |
289
|
|
|
|
290
|
|
|
for tag in [self.tag0, self.tag1]: |
291
|
|
|
self.test_runs[0].add_tag(tag) |
292
|
|
|
self.test_runs[1].add_tag(tag) |
293
|
|
|
|
294
|
|
|
def test_remove_tag(self): |
295
|
|
|
result = self.rpc_client.TestRun.remove_tag( |
296
|
|
|
self.test_runs[0].pk, self.tag0.name |
297
|
|
|
) |
298
|
|
|
self.assertEqual(len(result), 1) |
299
|
|
|
self.assertEqual(result[0]["id"], self.tag1.pk) |
300
|
|
|
self.assertEqual(result[0]["name"], self.tag1.name) |
301
|
|
|
|
302
|
|
|
tag_exists = TestRun.objects.filter( |
303
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag0.pk |
304
|
|
|
).exists() |
305
|
|
|
self.assertFalse(tag_exists) |
306
|
|
|
|
307
|
|
|
tag_exists = TestRun.objects.filter( |
308
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag1.pk |
309
|
|
|
).exists() |
310
|
|
|
self.assertTrue(tag_exists) |
311
|
|
|
|
312
|
|
View Code Duplication |
def test_remove_tag_without_permissions(self): |
|
|
|
|
313
|
|
|
unauthorized_user = UserFactory() |
314
|
|
|
unauthorized_user.set_password("api-testing") |
315
|
|
|
unauthorized_user.save() |
316
|
|
|
|
317
|
|
|
unauthorized_user.user_permissions.add(*Permission.objects.all()) |
318
|
|
|
remove_perm_from_user(unauthorized_user, "testruns.delete_testruntag") |
319
|
|
|
|
320
|
|
|
rpc_client = xmlrpc.TCMSXmlrpc( |
321
|
|
|
unauthorized_user.username, |
322
|
|
|
"api-testing", |
323
|
|
|
"%s/xml-rpc/" % self.live_server_url, |
324
|
|
|
).server |
325
|
|
|
|
326
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
327
|
|
|
rpc_client.TestRun.remove_tag(self.test_runs[0].pk, self.tag0.name) |
328
|
|
|
|
329
|
|
|
# tags were not modified |
330
|
|
|
tag_exists = TestRun.objects.filter( |
331
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag0.pk |
332
|
|
|
).exists() |
333
|
|
|
self.assertTrue(tag_exists) |
334
|
|
|
|
335
|
|
|
tag_exists = TestRun.objects.filter( |
336
|
|
|
pk=self.test_runs[0].pk, tag__pk=self.tag1.pk |
337
|
|
|
).exists() |
338
|
|
|
self.assertTrue(tag_exists) |
339
|
|
|
|
340
|
|
|
|
341
|
|
|
class TestRunCreate(APITestCase): |
342
|
|
|
def _fixture_setup(self): |
343
|
|
|
super()._fixture_setup() |
344
|
|
|
|
345
|
|
|
self.plan = TestPlanFactory(author=self.api_user) |
346
|
|
|
self.build = BuildFactory(version=self.plan.product_version) |
347
|
|
|
|
348
|
|
|
def test_create_with_invalid_value(self): |
349
|
|
|
test_run_fields = { |
350
|
|
|
"plan": self.plan.pk, |
351
|
|
|
"build": self.build.pk, |
352
|
|
|
"summary": "TR without version", |
353
|
|
|
"manager": "manager", |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Unknown user: "manager"'): |
357
|
|
|
self.rpc_client.TestRun.create(test_run_fields) |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
class TestCreatePermission(APIPermissionsTestCase): |
361
|
|
|
permission_label = "testruns.add_testrun" |
362
|
|
|
|
363
|
|
|
def _fixture_setup(self): |
364
|
|
|
super()._fixture_setup() |
365
|
|
|
|
366
|
|
|
self.plan = TestPlanFactory() |
367
|
|
|
self.build = BuildFactory(version=self.plan.product_version) |
368
|
|
|
|
369
|
|
|
self.test_run_fields = { |
370
|
|
|
"plan": self.plan.pk, |
371
|
|
|
"build": self.build.pk, |
372
|
|
|
"summary": "TR created", |
373
|
|
|
"manager": UserFactory().pk, |
374
|
|
|
"start_date": datetime.strptime("2020-05-05", "%Y-%m-%d"), |
375
|
|
|
"stop_date": datetime.strptime("2020-05-05 00:00:00", "%Y-%m-%d %H:%M:%S"), |
376
|
|
|
"planned_start": datetime.strptime( |
377
|
|
|
"2020-05-05 09:00:00", "%Y-%m-%d %H:%M:%S" |
378
|
|
|
), |
379
|
|
|
"planned_stop": datetime.strptime("2020-05-06", "%Y-%m-%d"), |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
def verify_api_with_permission(self): |
383
|
|
|
result = self.rpc_client.TestRun.create(self.test_run_fields) |
384
|
|
|
|
385
|
|
|
run_id = result["id"] |
386
|
|
|
test_run = TestRun.objects.get(pk=run_id) |
387
|
|
|
|
388
|
|
|
self.assertIn("id", result) |
389
|
|
|
self.assertEqual(result["summary"], self.test_run_fields["summary"]) |
390
|
|
|
self.assertIn("notes", result) |
391
|
|
|
self.assertEqual(result["stop_date"], test_run.stop_date) |
392
|
|
|
self.assertEqual(result["start_date"], test_run.start_date) |
393
|
|
|
self.assertEqual(result["planned_start"], test_run.planned_start) |
394
|
|
|
self.assertEqual(result["planned_stop"], test_run.planned_stop) |
395
|
|
|
self.assertEqual(result["plan"], self.plan.pk) |
396
|
|
|
self.assertEqual(result["build"], self.build.pk) |
397
|
|
|
self.assertEqual(result["manager"], self.test_run_fields["manager"]) |
398
|
|
|
self.assertIn("default_tester", result) |
399
|
|
|
|
400
|
|
|
def verify_api_without_permission(self): |
401
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
402
|
|
|
self.rpc_client.TestRun.create(self.test_run_fields) |
403
|
|
|
|
404
|
|
|
|
405
|
|
|
class TestFilter(APITestCase): |
406
|
|
|
def _fixture_setup(self): |
407
|
|
|
super()._fixture_setup() |
408
|
|
|
|
409
|
|
|
self.plan = TestPlanFactory() |
410
|
|
|
|
411
|
|
|
self.test_case = TestCaseFactory() |
412
|
|
|
self.test_case.save() |
413
|
|
|
self.plan.add_case(self.test_case) |
414
|
|
|
|
415
|
|
|
self.test_run = TestRunFactory(plan=self.plan) |
416
|
|
|
|
417
|
|
|
def test_empty_query(self): |
418
|
|
|
result = self.rpc_client.TestRun.filter() |
419
|
|
|
self.assertTrue(isinstance(result, list)) |
420
|
|
|
self.assertEqual(1, len(result)) |
421
|
|
|
self.assertEqual(self.test_run.pk, result[0]["id"]) |
422
|
|
|
|
423
|
|
|
def test_filter(self): |
424
|
|
|
_ = TestRunFactory() |
425
|
|
|
result = self.rpc_client.TestRun.filter({"plan": self.plan.pk}) |
426
|
|
|
self.assertEqual(1, len(result)) |
427
|
|
|
|
428
|
|
|
result = result[0] |
429
|
|
|
|
430
|
|
|
self.assertEqual(result["id"], self.test_run.pk) |
431
|
|
|
self.assertEqual( |
432
|
|
|
result["plan__product_version"], self.test_run.plan.product_version.pk |
433
|
|
|
) |
434
|
|
|
self.assertEqual( |
435
|
|
|
result["plan__product_version__value"], |
436
|
|
|
self.test_run.plan.product_version.value, |
437
|
|
|
) |
438
|
|
|
self.assertEqual(result["start_date"], self.test_run.start_date) |
439
|
|
|
self.assertEqual(result["stop_date"], self.test_run.stop_date) |
440
|
|
|
self.assertEqual(result["planned_start"], self.test_run.planned_start) |
441
|
|
|
self.assertEqual(result["planned_stop"], self.test_run.planned_stop) |
442
|
|
|
self.assertEqual(result["summary"], self.test_run.summary) |
443
|
|
|
self.assertEqual(result["notes"], self.test_run.notes) |
444
|
|
|
self.assertEqual(result["plan"], self.test_run.plan.pk) |
445
|
|
|
self.assertEqual(result["build"], self.test_run.build.pk) |
446
|
|
|
self.assertEqual(result["manager"], self.test_run.manager.pk) |
447
|
|
|
self.assertEqual(result["default_tester"], self.test_run.default_tester.pk) |
448
|
|
|
|
449
|
|
|
|
450
|
|
|
class TestFilterPermission(APIPermissionsTestCase): |
451
|
|
|
permission_label = "testruns.view_testrun" |
452
|
|
|
|
453
|
|
|
def verify_api_with_permission(self): |
454
|
|
|
result = self.rpc_client.TestRun.filter() |
455
|
|
|
self.assertTrue(isinstance(result, list)) |
456
|
|
|
|
457
|
|
|
def verify_api_without_permission(self): |
458
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
459
|
|
|
self.rpc_client.TestRun.filter(None) |
460
|
|
|
|
461
|
|
|
|
462
|
|
|
class TestUpdateTestRun(APITestCase): |
463
|
|
|
def _fixture_setup(self): |
464
|
|
|
super()._fixture_setup() |
465
|
|
|
|
466
|
|
|
self.test_run = TestRunFactory() |
467
|
|
|
|
468
|
|
|
self.updated_test_plan = TestPlanFactory() |
469
|
|
|
self.updated_build = BuildFactory() |
470
|
|
|
self.updated_summary = "Updated summary." |
471
|
|
|
self.updated_stop_date = datetime.strptime("2020-05-05", "%Y-%m-%d") |
472
|
|
|
self.updated_planned_start = datetime.strptime( |
473
|
|
|
"2020-05-05 09:00:00", "%Y-%m-%d %H:%M:%S" |
474
|
|
|
) |
475
|
|
|
self.updated_planned_stop = datetime.strptime("2020-05-06", "%Y-%m-%d") |
476
|
|
|
|
477
|
|
|
def test_successful_update(self): |
478
|
|
|
update_fields = { |
479
|
|
|
"plan": self.updated_test_plan.pk, |
480
|
|
|
"build": self.updated_build.pk, |
481
|
|
|
"summary": self.updated_summary, |
482
|
|
|
"stop_date": self.updated_stop_date, |
483
|
|
|
"planned_start": self.updated_planned_start, |
484
|
|
|
"planned_stop": self.updated_planned_stop, |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
# assert test run is not updated yet |
488
|
|
|
self.assertNotEqual(self.updated_test_plan, self.test_run.plan.name) |
489
|
|
|
self.assertNotEqual(self.updated_build, self.test_run.build.name) |
490
|
|
|
self.assertNotEqual(self.updated_summary, self.test_run.summary) |
491
|
|
|
self.assertNotEqual(self.updated_stop_date, self.test_run.stop_date) |
492
|
|
|
self.assertNotEqual(self.updated_planned_start, self.test_run.planned_start) |
493
|
|
|
self.assertNotEqual(self.updated_planned_stop, self.test_run.planned_stop) |
494
|
|
|
|
495
|
|
|
result = self.rpc_client.TestRun.update(self.test_run.pk, update_fields) |
496
|
|
|
self.test_run.refresh_from_db() |
497
|
|
|
|
498
|
|
|
# compare result, returned from API call with test run from DB |
499
|
|
|
self.assertEqual(result["id"], self.test_run.pk) |
500
|
|
|
self.assertEqual(result["start_date"], self.test_run.start_date) |
501
|
|
|
self.assertEqual(result["stop_date"], self.test_run.stop_date) |
502
|
|
|
self.assertEqual(result["planned_start"], self.test_run.planned_start) |
503
|
|
|
self.assertEqual(result["planned_stop"], self.test_run.planned_stop) |
504
|
|
|
self.assertEqual(result["summary"], self.test_run.summary) |
505
|
|
|
self.assertEqual(result["notes"], self.test_run.notes) |
506
|
|
|
self.assertEqual(result["plan"], self.test_run.plan.pk) |
507
|
|
|
self.assertEqual(result["build"], self.test_run.build.pk) |
508
|
|
|
self.assertEqual(result["manager"], self.test_run.manager.pk) |
509
|
|
|
self.assertEqual(result["default_tester"], self.test_run.default_tester.pk) |
510
|
|
|
|
511
|
|
|
def test_wrong_date_format(self): |
512
|
|
|
test_run = TestRunFactory() |
513
|
|
|
update_fields = { |
514
|
|
|
"plan": self.updated_test_plan.pk, |
515
|
|
|
"build": self.updated_build.pk, |
516
|
|
|
"summary": self.updated_summary, |
517
|
|
|
"stop_date": "10-10-2010", |
518
|
|
|
"planned_stop": "11-10-2010", |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
with self.assertRaisesMessage( |
522
|
|
|
Exception, str(_("Invalid date format. Expected YYYY-MM-DD [HH:MM:SS].")) |
523
|
|
|
): |
524
|
|
|
self.rpc_client.TestRun.update(test_run.pk, update_fields) |
525
|
|
|
|
526
|
|
|
# assert test run fields have not been updated |
527
|
|
|
test_run.refresh_from_db() |
528
|
|
|
self.assertNotEqual(update_fields["plan"], test_run.plan.pk) |
529
|
|
|
self.assertNotEqual(update_fields["build"], test_run.build.pk) |
530
|
|
|
self.assertNotEqual(update_fields["summary"], test_run.summary) |
531
|
|
|
self.assertNotEqual( |
532
|
|
|
datetime.strptime(update_fields["stop_date"], "%d-%m-%Y"), |
533
|
|
|
test_run.stop_date, |
534
|
|
|
) |
535
|
|
|
self.assertNotEqual( |
536
|
|
|
datetime.strptime(update_fields["planned_stop"], "%d-%m-%Y"), |
537
|
|
|
test_run.planned_stop, |
538
|
|
|
) |
539
|
|
|
|
540
|
|
|
def test_update_with_product(self): |
541
|
|
|
test_run = TestRunFactory() |
542
|
|
|
product = ProductFactory() |
543
|
|
|
updated_test_plan = TestPlanFactory(product=product) |
544
|
|
|
updated_build = BuildFactory(version=product.version.first()) |
545
|
|
|
updated_summary = "Updated summary." |
546
|
|
|
updated_stop_date = "2020-05-05 00:00:00" |
547
|
|
|
|
548
|
|
|
updated_test_run = self.rpc_client.TestRun.update( |
549
|
|
|
test_run.pk, |
550
|
|
|
{ |
551
|
|
|
"plan": updated_test_plan.pk, |
552
|
|
|
"product": product.id, |
553
|
|
|
"build": updated_build.pk, |
554
|
|
|
"summary": updated_summary, |
555
|
|
|
"stop_date": updated_stop_date, |
556
|
|
|
}, |
557
|
|
|
) |
558
|
|
|
|
559
|
|
|
test_run.refresh_from_db() |
560
|
|
|
|
561
|
|
|
self.assertEqual(updated_test_run["plan"], updated_test_plan.pk) |
562
|
|
|
self.assertEqual(updated_test_run["build"], updated_build.pk) |
563
|
|
|
self.assertEqual(updated_test_run["summary"], updated_summary) |
564
|
|
|
self.assertEqual(updated_test_run["stop_date"], test_run.stop_date) |
565
|
|
|
|
566
|
|
|
|
567
|
|
|
class TestUpdatePermission(APIPermissionsTestCase): |
568
|
|
|
permission_label = "testruns.change_testrun" |
569
|
|
|
|
570
|
|
|
def _fixture_setup(self): |
571
|
|
|
super()._fixture_setup() |
572
|
|
|
|
573
|
|
|
self.test_run = TestRunFactory() |
574
|
|
|
self.update_fields = { |
575
|
|
|
"plan": TestPlanFactory().pk, |
576
|
|
|
"build": BuildFactory().pk, |
577
|
|
|
"summary": "Updated summary.", |
578
|
|
|
"stop_date": "2020-05-05 00:00:00", |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
def verify_api_with_permission(self): |
582
|
|
|
updated_test_run = self.rpc_client.TestRun.update( |
583
|
|
|
self.test_run.pk, self.update_fields |
584
|
|
|
) |
585
|
|
|
self.test_run.refresh_from_db() |
586
|
|
|
|
587
|
|
|
self.assertEqual(updated_test_run["summary"], self.update_fields["summary"]) |
588
|
|
|
self.assertEqual(updated_test_run["stop_date"], self.test_run.stop_date) |
589
|
|
|
|
590
|
|
|
def verify_api_without_permission(self): |
591
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
592
|
|
|
self.rpc_client.TestRun.update(self.test_run.pk, self.update_fields) |
593
|
|
|
|