forked from kiwitcms/Kiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: Add tests for tcms.bugs.api.add_tag(). Refs kiwitcms#1597
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# pylint: disable=attribute-defined-outside-init | ||
|
||
from xmlrpc.client import Fault as XmlRPCFault | ||
from xmlrpc.client import ProtocolError | ||
|
||
from tcms.bugs.models import Bug | ||
from tcms.bugs.tests.factory import BugFactory | ||
from tcms.management.models import Tag | ||
from tcms.rpc.tests.utils import APIPermissionsTestCase | ||
from tcms.tests import user_should_have_perm | ||
from tcms.tests.factories import TagFactory | ||
|
||
|
||
class TestAddTag(APIPermissionsTestCase): | ||
"""Test Bug.add_tag""" | ||
|
||
permission_label = 'bugs.add_bug_tags' | ||
|
||
def _fixture_setup(self): | ||
super()._fixture_setup() | ||
|
||
self.bug = BugFactory() | ||
self.tag = TagFactory(name='rhel') | ||
|
||
def verify_api_with_permission(self): | ||
self.rpc_client.Bug.add_tag(self.bug.pk, self.tag.name) | ||
self.assertIn(self.tag, Bug.objects.get(pk=self.bug.pk).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) | ||
|
||
def test_add_tag_to_non_existent_bug(self): | ||
user_should_have_perm(self.tester, self.permission_label) | ||
with self.assertRaisesRegex(XmlRPCFault, 'Bug matching query does not exist'): | ||
self.rpc_client.Bug.add_tag(-9, self.tag.name) | ||
|
||
def test_add_non_existent_tag_with_add_tag_perm(self): | ||
user_should_have_perm(self.tester, self.permission_label) | ||
user_should_have_perm(self.tester, 'management.add_tag') | ||
|
||
self.assertFalse(Tag.objects.filter(name='fedora').exists()) | ||
self.rpc_client.Bug.add_tag(self.bug.pk, 'fedora') | ||
self.assertTrue(Tag.objects.filter(name='fedora').exists()) | ||
self.assertTrue(self.bug.tags.filter(name='fedora').exists()) | ||
|
||
def test_add_non_existent_tag_without_add_tags_perm(self): | ||
user_should_have_perm(self.tester, self.permission_label) | ||
|
||
with self.assertRaisesRegex(XmlRPCFault, 'Tag matching query does not exist'): | ||
self.rpc_client.Bug.add_tag(self.bug.pk, 'fedora') |