예제 #1
0
    def test_add_reopen_bug_comment(self):
        old_comment_count = get_comments(self.bug).count()

        self.client.post(
            self.url, {"bug": self.bug.pk, "text": "", "action": "reopen"}, follow=True
        )
        comments = get_comments(self.bug)

        self.assertEqual(comments.count(), old_comment_count + 1)
        self.assertEqual(comments.last().comment, _("*bug reopened*"))
예제 #2
0
    def test_add_reopen_bug_comment(self):
        old_comment_count = get_comments(self.bug).count()

        self.client.post(
            self.url,
            {'bug': self.bug.pk, 'text': '', 'action': 'reopen'},
            follow=True
        )
        comments = get_comments(self.bug)

        self.assertEqual(comments.count(), old_comment_count + 1)
        self.assertEqual(comments.last().comment, _('*bug reopened*'))
예제 #3
0
def handle_comments_pre_delete(sender, **kwargs):
    """
        Delete comments attached to object which is about to be
        deleted b/c django-comments' object_pk is not a FK relationship
        and we can't rely on cascading delete!
    """
    from tcms.core.helpers.comments import get_comments

    if kwargs.get('raw', False):
        return

    instance = kwargs['instance']

    get_comments(instance).delete()
예제 #4
0
    def verify_post_with_permission(self):
        old_comment_count = get_comments(self.bug).count()

        response = self.client.post(self.url, self.post_data, follow=True)
        comments = get_comments(self.bug)

        self.assertRedirects(
            response,
            reverse("bugs-get", args=(self.bug.pk,)),
            status_code=302,
            target_status_code=200,
        )

        self.assertEqual(comments.count(), old_comment_count + 1)
        self.assertEqual(comments.last().comment, "A comment text")
예제 #5
0
    def test_delete_all_comments(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        comments.add_comment([self.execution], "More comments", self.user)
        self.rpc_client.TestExecution.remove_comment(self.execution.pk)

        result = comments.get_comments(self.execution)
        self.assertEqual(result.count(), 0)
예제 #6
0
    def test_report_issue_from_test_execution_1click_works(self):
        # simulate user clicking the 'Report bug' button in TE widget, TR page
        result = self.rpc_client.Bug.report(
            self.execution_1.pk, self.integration.bug_system.pk
        )
        self.assertEqual(result["rc"], 0)
        self.assertIn(self.integration.bug_system.base_url, result["response"])
        self.assertIn("/bugs/", result["response"])

        new_bug_id = self.integration.bug_id_from_url(result["response"])
        bug = Bug.objects.get(pk=new_bug_id)

        self.assertEqual(f"Failed test: {self.execution_1.case.summary}", bug.summary)
        first_comment = get_comments(bug).first()
        for expected_string in [
            f"Filed from execution {self.execution_1.get_full_url()}",
            self.execution_1.run.plan.product.name,
            self.component.name,
            "Steps to reproduce",
            self.execution_1.case.text,
        ]:
            self.assertIn(expected_string, first_comment.comment)

        # verify that LR has been added to TE
        self.assertTrue(
            LinkReference.objects.filter(
                execution=self.execution_1,
                url=result["response"],
                is_defect=True,
            ).exists()
        )
예제 #7
0
    def test_notify_assignee_on_bug_creation(self, send_mail):  # pylint: disable=no-self-use
        assignee = UserFactory()
        bug = BugFactory(assignee=assignee)

        expected_subject = _("Bug #%(pk)d - %(summary)s") % {
            "pk": bug.pk,
            "summary": bug.summary,
        }
        expected_body = render_to_string(
            "email/post_bug_save/email.txt",
            {
                "bug": bug,
                "comment": get_comments(bug).last()
            },
        )
        expected_recipients = [assignee.email, bug.reporter.email]
        expected_recipients.sort()

        send_mail.assert_called_once_with(
            settings.EMAIL_SUBJECT_PREFIX + expected_subject,
            expected_body,
            settings.DEFAULT_FROM_EMAIL,
            expected_recipients,
            fail_silently=False,
        )
예제 #8
0
    def get_context_data(self, **kwargs):
        data = super().get_context_data(**kwargs)

        case = TestCase.objects.get(pk=kwargs['case_id'])
        execution = TestExecution.objects.get(pk=self.execution_id)

        # Data of TestCase
        test_case_text = case.get_text_with_version(self.case_text_version)

        # Data of TestExecution
        execution_comments = get_comments(execution)

        execution_status = TestExecutionStatus.objects.order_by('-weight', 'name')

        data.update({
            'test_case': case,
            'test_case_text': test_case_text,

            'execution': execution,
            'comments_count': len(execution_comments),
            'execution_comments': execution_comments,
            'execution_logs': execution.history.all(),
            'execution_status': execution_status,
        })

        return data
예제 #9
0
def handle_emails_post_bug_save(sender, instance, created=False, **kwargs):
    from tcms.core.helpers.comments import get_comments
    from tcms.core.utils.mailto import mailto

    comments = get_comments(instance)

    recipients = set(comments.values_list("user_email", flat=True))
    recipients.add(instance.reporter.email)

    if instance.assignee:
        recipients.add(instance.assignee.email)

    if not recipients:
        return

    mailto(
        template_name="email/post_bug_save/email.txt",
        recipients=list(recipients),
        subject=_("Bug #%(pk)d - %(summary)s") % {
            "pk": instance.pk,
            "summary": instance.summary
        },
        context={
            "bug": instance,
            "comment": comments.last(),
        },
    )
예제 #10
0
    def test_add_comment_with_pk_as_int(self):
        self.rpc_client.exec.TestExecution.add_comment(self.execution_2.pk,
                                                       "Hello World!")
        comments = get_comments(self.execution_2)
        self.assertEqual(1, comments.count())

        first_comment = comments.first()
        self.assertEqual("Hello World!", first_comment.comment)
예제 #11
0
    def test_add_comment_with_pk_as_int(self):
        created_comment = self.rpc_client.TestExecution.add_comment(
            self.execution_2.pk, "Hello World!")
        execution_comments = comments.get_comments(self.execution_2)
        self.assertEqual(1, execution_comments.count())

        first_comment = execution_comments.first()
        self.assertEqual("Hello World!", first_comment.comment)
        self.assertEqual(created_comment["comment"], first_comment.comment)
예제 #12
0
    def test_delete_one_comment(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        comment_2 = comments.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"])
        result = comments.get_comments(self.execution)
        first_comment = result.first()

        self.assertEqual(result.count(), 1)
        self.assertEqual("Hello World!", first_comment.comment)
예제 #13
0
    def test_record_changes(self):
        old_summary = self.bug.summary
        new_summary = "An edited summary"
        old_comment_count = get_comments(self.bug).count()

        edit_data = {
            "summary": new_summary,
            "version": self.bug.version.pk,
            "build": self.bug.build.pk,
            "reporter": self.bug.reporter.pk,
            "assignee": self.bug.assignee.pk,
            "product": self.bug.product.pk,
        }

        self.client.post(self.url, edit_data, follow=True)
        self.bug.refresh_from_db()
        comments = get_comments(self.bug)

        self.assertEqual(comments.count(), old_comment_count + 1)
        self.assertEqual(comments.last().comment,
                         "Summary: %s -> %s\n" % (old_summary, new_summary))
예제 #14
0
    def test_record_changes(self):
        old_summary = self.bug.summary
        new_summary = 'An edited summary'
        old_comment_count = get_comments(self.bug).count()

        edit_data = {
            'summary': new_summary,
            'version': self.bug.version.pk,
            'build': self.bug.build.pk,
            'reporter': self.bug.reporter.pk,
            'assignee': self.bug.assignee.pk,
            'product': self.bug.product.pk
        }

        self.client.post(self.url, edit_data, follow=True)
        self.bug.refresh_from_db()
        comments = get_comments(self.bug)

        self.assertEqual(comments.count(), old_comment_count + 1)
        self.assertEqual(comments.last().comment,
                         "Summary: %s -> %s\n" % (old_summary, new_summary))
예제 #15
0
def get_comments(execution_id):
    """
    .. function:: RPC TestExecution.get_comments(execution_id)

        Get all comments for selected test execution.

        :param execution_id: PK of a TestExecution object
        :type execution_id: int
        :return: Serialized :class:`django_comments.models.Comment` object
        :rtype: dict
        :raises PermissionDenied: if missing *django_comments.view_comment* permission
    """
    execution = TestExecution.objects.get(pk=execution_id)
    execution_comments = comments.get_comments(execution).values()
    return list(execution_comments)
예제 #16
0
def remove_comment(execution_id, comment_id=None):
    """
    .. function:: RPC TestExecution.remove_comment(execution_id, comment_id)

        Remove all or specified comment(s) from selected test execution.

        :param execution_id: PK of a TestExecution object
        :type execution_id: int
        :param comment_id: PK of a Comment object or None
        :type comment_id: int
        :raises PermissionDenied: if missing *django_comments.delete_comment* permission
    """
    execution = TestExecution.objects.get(pk=execution_id)
    to_be_deleted = comments.get_comments(execution)
    if comment_id:
        to_be_deleted = to_be_deleted.filter(pk=comment_id)

    to_be_deleted.delete()
예제 #17
0
    def test_email_sent_to_all_commenters(self, send_mail):
        bug = BugFactory(assignee=self.assignee, reporter=self.tester)
        commenter = UserFactory()
        tracker = UserFactory()
        add_comment([bug], _("*bug created*"), tracker)
        add_comment([bug], _("*bug created*"), commenter)

        expected_body = render_to_string(
            "email/post_bug_save/email.txt",
            {
                "bug": bug,
                "comment": get_comments(bug).last()
            },
        )
        expected_recipients = [
            self.assignee.email,
            self.tester.email,
            commenter.email,
            tracker.email,
        ]
        expected_recipients.sort()

        expected_subject = _("Bug #%(pk)d - %(summary)s") % {
            "pk": bug.pk,
            "summary": bug.summary,
        }

        self.assertTrue(send_mail.called)
        self.assertEqual(
            settings.EMAIL_SUBJECT_PREFIX + expected_subject,
            send_mail.call_args.args[0],
        )
        self.assertEqual(expected_body, send_mail.call_args.args[1])
        self.assertEqual(settings.DEFAULT_FROM_EMAIL,
                         send_mail.call_args.args[2])
        self.assertTrue(
            len(send_mail.call_args.args[3]) == len(expected_recipients))
        self.assertIn(expected_recipients[0], send_mail.call_args.args[3])
        self.assertIn(expected_recipients[1], send_mail.call_args.args[3])
예제 #18
0
    def test_email_sent_when_bug_reopened(self, send_mail):
        bug = BugFactory(assignee=self.assignee, reporter=self.tester)
        bug.status = False
        bug.save()
        self.client.post(self.url, {
            "bug": bug.pk,
            "text": "",
            "action": "reopen"
        },
                         follow=True)

        expected_body = render_to_string(
            "email/post_bug_save/email.txt",
            {
                "bug": bug,
                "comment": get_comments(bug).last()
            },
        )
        expected_recipients = [self.assignee.email, self.tester.email]
        expected_recipients.sort()

        expected_subject = _("Bug #%(pk)d - %(summary)s") % {
            "pk": bug.pk,
            "summary": bug.summary,
        }

        self.assertTrue(send_mail.called)
        self.assertEqual(
            settings.EMAIL_SUBJECT_PREFIX + expected_subject,
            send_mail.call_args.args[0],
        )
        self.assertEqual(expected_body, send_mail.call_args.args[1])
        self.assertEqual(settings.DEFAULT_FROM_EMAIL,
                         send_mail.call_args.args[2])
        self.assertTrue(
            len(send_mail.call_args.args[3]) == len(expected_recipients))
        self.assertIn(expected_recipients[0], send_mail.call_args.args[3])
        self.assertIn(expected_recipients[1], send_mail.call_args.args[3])
예제 #19
0
    def verify_api_with_permission(self):
        comments.add_comment([self.execution], "Hello World!", self.user)
        self.rpc_client.TestExecution.remove_comment(self.execution.pk)

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