Skip to content

Commit

Permalink
add test for TestExecution.remove_comment . Fix #1625
Browse files Browse the repository at this point in the history
  • Loading branch information
awalvie committed Oct 31, 2020
1 parent 8f936cf commit 90dfa13
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tcms/rpc/tests/test_testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from django.utils import timezone

from tcms.core.contrib.linkreference.models import LinkReference
from tcms.core.helpers.comments import get_comments
from django.forms.models import model_to_dict
from tcms.core.helpers.comments import get_comments, add_comment
from tcms.rpc.tests.utils import APITestCase, APIPermissionsTestCase
from tcms.testruns.models import TestExecutionStatus
from tcms.tests.factories import BuildFactory
Expand Down Expand Up @@ -37,6 +38,61 @@ def test_add_comment_with_pk_as_int(self):
self.assertEqual(created_comment['comment'], first_comment.comment)


class TestExecutionRemoveComment(APITestCase):
"""Test TestExecution.remove_comment"""

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

self.user = UserFactory()
self.execution = TestExecutionFactory()

def test_delete_all_comments(self):
add_comment([self.execution], "Hello World!", self.user)
add_comment([self.execution], "More comments", self.user)
self.rpc_client.TestExecution.remove_comment(self.execution.pk)

comments = get_comments(self.execution)
self.assertEqual(comments.count(), 0)

def test_delete_one_comment(self):
add_comment([self.execution], "Hello World!", self.user)
comment_2 = add_comment([self.execution], "More comments", self.user)
comment_2 = model_to_dict(comment_2[0])

self.rpc_client.TestExecution.remove_comment(self.execution.pk, comment_2['id'])
comments = get_comments(self.execution)
first_comment = comments.first()

self.assertEqual(comments.count(), 1)
self.assertEqual("Hello World!", first_comment.comment)


class TestExecutionRemoveCommentPermissions(APIPermissionsTestCase):
"""Test TestExecution.remove_comment permissions"""

permission_label = 'django_comments.delete_comment'

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

self.user = UserFactory()
self.execution = TestExecutionFactory()

def verify_api_with_permission(self):
add_comment([self.execution], "Hello World!", self.user)
self.rpc_client.TestExecution.remove_comment(self.execution.pk)

comments = get_comments(self.execution)
self.assertEqual(comments.count(), 0)

def verify_api_without_permission(self):
add_comment([self.execution], "Hello World!", self.user)

with self.assertRaisesRegex(ProtocolError, '403 Forbidden'):
self.rpc_client.TestExecution.remove_comment(self.execution.pk)


@override_settings(LANGUAGE_CODE='en')
class TestExecutionAddLink(APITestCase):
"""Test TestExecution.add_link"""
Expand Down

0 comments on commit 90dfa13

Please sign in to comment.