1
|
|
|
from http import HTTPStatus |
2
|
|
|
|
3
|
|
|
from django.urls import reverse |
4
|
|
|
|
5
|
|
|
from tcms.testplans.models import TestPlan |
6
|
|
|
from tcms.testplans.tests.tests import BasePlanTest |
7
|
|
|
from tcms.tests import remove_perm_from_user, user_should_have_perm |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
class NewPlanViewTest(BasePlanTest): |
11
|
|
|
location = reverse('plans-new') |
12
|
|
|
plan_name = 'plan name' |
13
|
|
|
add_testplan_permission = 'testplans.add_testplan' |
14
|
|
|
|
15
|
|
|
def setUp(self): |
16
|
|
|
super().setUp() |
17
|
|
|
|
18
|
|
|
user_should_have_perm(self.user, perm=self.add_testplan_permission) |
19
|
|
|
|
20
|
|
|
self.user.is_superuser = False |
21
|
|
|
self.user.save() |
22
|
|
|
|
23
|
|
|
self.request = { |
24
|
|
|
'product': self.product.id, |
25
|
|
|
'product_version': self.product_version.id, |
26
|
|
|
'type': self.plan_type.pk, |
27
|
|
|
'name': self.plan_name, |
28
|
|
|
'auto_to_plan_author': True, |
29
|
|
|
'auto_to_case_owner': True, |
30
|
|
|
'auto_to_case_default_tester': True, |
31
|
|
|
'notify_on_case_update': False, |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
def test_plan_new_get(self): |
35
|
|
|
response = self.client.get(self.location, follow=True) |
36
|
|
|
|
37
|
|
|
self.assertEqual(response.status_code, HTTPStatus.OK) |
38
|
|
|
self.assertContains( |
39
|
|
|
response, |
40
|
|
|
'<input class="bootstrap-switch" name="is_active" type="checkbox" checked>', |
41
|
|
|
html=True) |
42
|
|
|
self.assertContains( |
43
|
|
|
response, |
44
|
|
|
'<input class="bootstrap-switch" name="auto_to_plan_author" type="checkbox" ' |
45
|
|
|
'checked>', html=True) |
46
|
|
|
self.assertContains( |
47
|
|
|
response, |
48
|
|
|
'<input class="bootstrap-switch" name="auto_to_case_owner" type="checkbox" ' |
49
|
|
|
'checked>', html=True) |
50
|
|
|
self.assertContains( |
51
|
|
|
response, |
52
|
|
|
'<input class="bootstrap-switch" name="auto_to_case_default_tester" type="checkbox" ' |
53
|
|
|
'checked>', html=True) |
54
|
|
|
self.assertContains( |
55
|
|
|
response, |
56
|
|
|
'<input class="bootstrap-switch" name="notify_on_plan_update" type="checkbox" ' |
57
|
|
|
'checked>', html=True) |
58
|
|
|
self.assertContains( |
59
|
|
|
response, |
60
|
|
|
'<input class="bootstrap-switch" name="notify_on_case_update" type="checkbox" ' |
61
|
|
|
'checked>', html=True) |
62
|
|
|
|
63
|
|
|
def test_plan_create_new_active(self): |
64
|
|
|
self._test_plan_create_new(is_active=True) |
65
|
|
|
|
66
|
|
|
def test_plan_create_new_inactive(self): |
67
|
|
|
self._test_plan_create_new(is_active=False) |
68
|
|
|
|
69
|
|
|
def _test_plan_create_new(self, is_active): |
70
|
|
|
self.request['is_active'] = is_active |
71
|
|
|
|
72
|
|
|
response = self.client.post(self.location, self.request, follow=True) |
73
|
|
|
self.assertEqual(response.status_code, HTTPStatus.OK) |
74
|
|
|
|
75
|
|
|
plan = TestPlan.objects.get(name=self.plan_name) |
76
|
|
|
self.assertEqual(plan.product, self.product) |
77
|
|
|
self.assertEqual(plan.product_version, self.product_version) |
78
|
|
|
self.assertEqual(plan.type, self.plan_type) |
79
|
|
|
self.assertEqual(plan.is_active, is_active) |
80
|
|
|
self.assertTrue(plan.emailing.auto_to_plan_author) |
81
|
|
|
self.assertTrue(plan.emailing.auto_to_case_owner) |
82
|
|
|
self.assertTrue(plan.emailing.auto_to_case_default_tester) |
83
|
|
|
self.assertFalse(plan.emailing.notify_on_plan_update) |
84
|
|
|
self.assertFalse(plan.emailing.notify_on_case_update) |
85
|
|
|
|
86
|
|
|
def test_get_with_no_perm_redirects_to_login(self): |
87
|
|
|
remove_perm_from_user(self.user, self.add_testplan_permission) |
88
|
|
|
|
89
|
|
|
response = self.client.get(self.location, follow=True) |
90
|
|
|
|
91
|
|
|
self.assertRedirects(response, reverse('tcms-login') + '?next=' + self.location) |
92
|
|
|
|
93
|
|
|
def test_post_with_no_perm_redirects_to_login(self): |
94
|
|
|
remove_perm_from_user(self.user, self.add_testplan_permission) |
95
|
|
|
|
96
|
|
|
response = self.client.post(self.location, self.request, follow=True) |
97
|
|
|
|
98
|
|
|
self.assertRedirects(response, reverse('tcms-login') + '?next=' + self.location) |
99
|
|
|
|