1
|
|
|
# pylint: disable=attribute-defined-outside-init |
2
|
|
|
# pylint: disable=wrong-import-position |
3
|
|
|
import unittest |
4
|
|
|
from xmlrpc.client import Fault as XmlRPCFault |
5
|
|
|
from xmlrpc.client import ProtocolError |
6
|
|
|
|
7
|
|
|
from django.conf import settings |
8
|
|
|
|
9
|
|
|
if "tcms.bugs.apps.AppConfig" not in settings.INSTALLED_APPS: |
10
|
|
|
raise unittest.SkipTest("tcms.bugs is disabled") |
11
|
|
|
|
12
|
|
|
from tcms.bugs.tests.factory import BugFactory # noqa: E402 |
13
|
|
|
from tcms.rpc.tests.utils import APITestCase, APIPermissionsTestCase # noqa: E402 |
14
|
|
|
from tcms.tests.factories import TagFactory # noqa: E402 |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class TestAddTagPermissions(APIPermissionsTestCase): |
18
|
|
|
"""Test Bug.add_tag""" |
19
|
|
|
|
20
|
|
|
permission_label = "bugs.add_bug_tags" |
21
|
|
|
|
22
|
|
|
def _fixture_setup(self): |
23
|
|
|
super()._fixture_setup() |
24
|
|
|
|
25
|
|
|
self.bug = BugFactory() |
26
|
|
|
self.tag = TagFactory() |
27
|
|
|
|
28
|
|
|
def verify_api_with_permission(self): |
29
|
|
|
self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name) |
30
|
|
|
self.assertIn(self.tag, self.bug.tags.all()) |
31
|
|
|
|
32
|
|
|
def verify_api_without_permission(self): |
33
|
|
|
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"): |
34
|
|
|
self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name) |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class TestAddTag(APITestCase): |
38
|
|
|
"""Test Bug.add_tag""" |
39
|
|
|
|
40
|
|
|
def _fixture_setup(self): |
41
|
|
|
super()._fixture_setup() |
42
|
|
|
|
43
|
|
|
self.bug = BugFactory() |
44
|
|
|
self.tag = TagFactory() |
45
|
|
|
|
46
|
|
|
def test_add_tag_to_non_existent_bug(self): |
47
|
|
|
with self.assertRaisesRegex(XmlRPCFault, 'Bug matching query does not exist'): |
48
|
|
|
self.rpc_client.Bug.add_tag(-9, self.tag.name) |
49
|
|
|
|