@@ 16-58 (lines=43) @@ | ||
13 | from tcms.utils.permissions import initiate_user_with_default_setups |
|
14 | ||
15 | ||
16 | class TestViewCaseTags(BasePlanCase): |
|
17 | @classmethod |
|
18 | def setUpTestData(cls): |
|
19 | super().setUpTestData() |
|
20 | ||
21 | initiate_user_with_default_setups(cls.tester) |
|
22 | for _i in range(3): |
|
23 | cls.case.add_tag(TagFactory()) |
|
24 | ||
25 | cls.unauthorized = UserFactory() |
|
26 | cls.unauthorized.set_password('password') |
|
27 | cls.unauthorized.save() |
|
28 | ||
29 | cls.unauthorized.user_permissions.add(*Permission.objects.all()) |
|
30 | remove_perm_from_user(cls.unauthorized, 'testcases.add_testcasetag') |
|
31 | remove_perm_from_user(cls.unauthorized, 'testcases.delete_testcasetag') |
|
32 | ||
33 | def test_view_tags_with_permissions(self): |
|
34 | url = reverse('ajax-tags') |
|
35 | response = self.client.get(url, {'case': self.case.pk}) |
|
36 | self.assertEqual(HTTPStatus.OK, response.status_code) |
|
37 | ||
38 | # assert tag actions are shown |
|
39 | self.assertContains(response, _('Add Tag')) |
|
40 | self.assertContains(response, |
|
41 | 'class="remove js-remove-tag" title="remove tag">%s</a>' % |
|
42 | _('Remove')) |
|
43 | ||
44 | def test_view_tags_without_permissions(self): |
|
45 | self.client.logout() |
|
46 | ||
47 | self.client.login( # nosec:B106:hardcoded_password_funcarg |
|
48 | username=self.unauthorized.username, |
|
49 | password='password') |
|
50 | ||
51 | url = reverse('ajax-tags') |
|
52 | response = self.client.get(url, {'case': self.case.pk}) |
|
53 | self.assertEqual(HTTPStatus.OK, response.status_code) |
|
54 | ||
55 | # assert tag actions are shown |
|
56 | self.assertNotContains(response, _('Add Tag')) |
|
57 | self.assertContains(response, |
|
58 | '<span class="disabled grey">%s</span>' % _('Remove')) |
|
59 |
@@ 17-58 (lines=42) @@ | ||
14 | from tcms.utils.permissions import initiate_user_with_default_setups |
|
15 | ||
16 | ||
17 | class TestViewPlanTags(BasePlanCase): |
|
18 | @classmethod |
|
19 | def setUpTestData(cls): |
|
20 | super().setUpTestData() |
|
21 | ||
22 | initiate_user_with_default_setups(cls.tester) |
|
23 | for _i in range(3): |
|
24 | cls.plan.add_tag(TagFactory()) |
|
25 | ||
26 | cls.unauthorized = UserFactory() |
|
27 | cls.unauthorized.set_password('password') |
|
28 | cls.unauthorized.save() |
|
29 | ||
30 | cls.unauthorized.user_permissions.add(*Permission.objects.all()) |
|
31 | remove_perm_from_user(cls.unauthorized, 'testplans.add_testplantag') |
|
32 | remove_perm_from_user(cls.unauthorized, 'testplans.delete_testplantag') |
|
33 | ||
34 | def test_view_tags_with_permissions(self): |
|
35 | url = reverse('ajax-tags') |
|
36 | response = self.client.get(url, {'plan': self.plan.pk}, follow=True) |
|
37 | self.assertEqual(HTTPStatus.OK, response.status_code) |
|
38 | ||
39 | # assert tag actions are shown |
|
40 | self.assertContains(response, _('Add Tag')) |
|
41 | self.assertContains(response, |
|
42 | 'class="remove js-remove-tag" title="remove tag">%s</a>' % |
|
43 | _('Remove')) |
|
44 | ||
45 | def test_view_tags_without_permissions(self): |
|
46 | self.client.logout() |
|
47 | ||
48 | self.client.login( # nosec:B106:hardcoded_password_funcarg |
|
49 | username=self.unauthorized.username, |
|
50 | password='password') |
|
51 | ||
52 | url = reverse('ajax-tags') |
|
53 | response = self.client.get(url, {'plan': self.plan.pk}, follow=True) |
|
54 | self.assertEqual(HTTPStatus.OK, response.status_code) |
|
55 | ||
56 | # assert tag actions are shown |
|
57 | self.assertNotContains(response, 'Add Tag') |
|
58 | self.assertContains(response, '<span class="disabled grey">%s</span>' % _('Remove')) |
|
59 |