Skip to content

Commit

Permalink
api: Add tests for tcms.bugs.api.add_tag -- Refs #1597
Browse files Browse the repository at this point in the history
  • Loading branch information
mfonism authored and atodorov committed Jul 9, 2020
1 parent 4d7f400 commit 4d50b1c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tcms/bugs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)


@permissions_required('bugs.add_bugtag')
@permissions_required('bugs.add_bug_tags')
@rpc_method(name='Bug.add_tag')
def add_tag(bug_id, tag, **kwargs):
"""
Expand All @@ -28,7 +28,7 @@ def add_tag(bug_id, tag, **kwargs):
:type tag: str
:param kwargs: Dict providing access to the current request, protocol
entry point name and handler instance from the rpc method
:raises PermissionDenied: if missing *bugs.add_bugtag* permission
:raises PermissionDenied: if missing *bugs.add_bug_tags* permission
:raises Bug.DoesNotExist: if object specified by PK doesn't exist
:raises Tag.DoesNotExist: if missing *management.add_tag* permission and *tag*
doesn't exist in the database!
Expand Down
48 changes: 48 additions & 0 deletions tcms/bugs/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# pylint: disable=attribute-defined-outside-init
# pylint: disable=wrong-import-position
import unittest
from xmlrpc.client import Fault as XmlRPCFault
from xmlrpc.client import ProtocolError

from django.conf import settings

if "tcms.bugs.apps.AppConfig" not in settings.INSTALLED_APPS:
raise unittest.SkipTest("tcms.bugs is disabled")

from tcms.bugs.tests.factory import BugFactory # noqa: E402
from tcms.rpc.tests.utils import APITestCase, APIPermissionsTestCase # noqa: E402
from tcms.tests.factories import TagFactory # noqa: E402


class TestAddTagPermissions(APIPermissionsTestCase):
"""Test Bug.add_tag"""

permission_label = "bugs.add_bug_tags"

def _fixture_setup(self):
super()._fixture_setup()

self.bug = BugFactory()
self.tag = TagFactory()

def verify_api_with_permission(self):
self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name)
self.assertIn(self.tag, self.bug.tags.all())

def verify_api_without_permission(self):
with self.assertRaisesRegex(ProtocolError, "403 Forbidden"):
self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name)


class TestAddTag(APITestCase):
"""Test Bug.add_tag"""

def _fixture_setup(self):
super()._fixture_setup()

self.bug = BugFactory()
self.tag = TagFactory()

def test_add_tag_to_non_existent_bug(self):
with self.assertRaisesRegex(XmlRPCFault, 'Bug matching query does not exist'):
self.rpc_client.Bug.add_tag(-9, self.tag.name)

0 comments on commit 4d50b1c

Please sign in to comment.