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

TestViewCaseTags.test_view_tags_with_permissions()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 10
Ratio 100 %

Importance

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