Passed
Push — master ( cddcf6...1d3855 )
by Alexander
01:59
created

TestViewPlanTags.test_view_tags_without_permissions()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 10
dl 14
loc 14
rs 9.9
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
# pylint: disable=too-many-ancestors
3
4
from http import HTTPStatus
5
6
from django.urls import reverse
7
from django.contrib.auth.models import Permission
8
from django.utils.translation import ugettext_lazy as _
9
10
from tcms.tests.factories import TagFactory
11
from tcms.tests.factories import UserFactory
12
from tcms.tests import remove_perm_from_user
13
from tcms.tests import BasePlanCase
14
from tcms.utils.permissions import initiate_user_with_default_setups
15
16
17 View Code Duplication
class TestViewPlanTags(BasePlanCase):
0 ignored issues
show
Duplication introduced by Mr. Senko
This code seems to be duplicated in your project.
Loading history...
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