def test_put_reply_with_diff_comment_and_local_site_no_access(self):
        """Testing the
        PUT review-requests/<id>/reviews/<id>/replies/<id>/diff-comments/ API
        with a local site and Permission Denied error
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user=self.user)
        reply_comment = self.create_diff_comment(
            reply, filediff, reply_to=comment)

        self._login_user()

        rsp = self.apiPut(
            get_review_reply_diff_comment_item_url(
                reply, reply_comment.pk, self.local_site_name),
            {'text': 'My new comment text'},
            expected_status=403)
        self.assertEqual(rsp['stat'], 'fail')
        self.assertEqual(rsp['err']['code'], PERMISSION_DENIED.code)
    def test_put_reply_with_diff_comment_and_local_site(self):
        """Testing the
        PUT review-requests/<id>/reviews/<id>/replies/<id>/diff-comments/ API
        with a local site
        """
        new_comment_text = 'My new comment text'
        user = self._login_user(local_site=True)
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    with_local_site=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user=user)
        reply_comment = self.create_diff_comment(
            reply, filediff, reply_to=comment)

        rsp = self.apiPut(
            get_review_reply_diff_comment_item_url(
                reply, reply_comment.pk, self.local_site_name),
            {'text': new_comment_text},
            expected_mimetype=review_reply_diff_comment_item_mimetype)
        self.assertEqual(rsp['stat'], 'ok')

        reply_comment = Comment.objects.get(pk=rsp['diff_comment']['id'])
        self.assertEqual(reply_comment.text, new_comment_text)
    def setup_basic_delete_test(self, user, with_local_site, local_site_name):
        review_request = self.create_review_request(
            create_repository=True, with_local_site=with_local_site, submitter=user, publish=True
        )
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request, user=user, publish=True)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user=user)
        reply_comment = self.create_diff_comment(reply, filediff, reply_to=comment)

        return (
            get_review_reply_diff_comment_item_url(reply, reply_comment.pk, local_site_name),
            [reply_comment, reply],
        )
    def setup_basic_put_test(self, user, with_local_site, local_site_name, put_valid_data):
        review_request = self.create_review_request(
            create_repository=True, with_local_site=with_local_site, submitter=user, publish=True
        )
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request, user=user, publish=True)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user=user)
        reply_comment = self.create_diff_comment(reply, filediff, reply_to=comment)

        return (
            get_review_reply_diff_comment_item_url(reply, reply_comment.pk, local_site_name),
            review_reply_diff_comment_item_mimetype,
            {"text": "Test comment"},
            reply_comment,
            [],
        )
    def test_delete_no_access(self):
        """Testing the DELETE
        review-requests/<id>/reviews/<id>/replies/<id>/diff-comments/<id>/ API
        and Permission Denied
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user='doc')
        reply_comment = self.create_diff_comment(
            reply, filediff, reply_to=comment)

        self.apiDelete(
            get_review_reply_diff_comment_item_url(reply, reply_comment.pk),
            expected_status=403)
    def test_delete(self):
        """Testing the DELETE
        review-requests/<id>/reviews/<id>/replies/<id>/diff-comments/<id>/ API
        """
        review_request = self.create_review_request(submitter=self.user,
                                                    create_repository=True,
                                                    publish=True)
        diffset = self.create_diffset(review_request)
        filediff = self.create_filediff(diffset)
        review = self.create_review(review_request)
        comment = self.create_diff_comment(review, filediff)
        reply = self.create_reply(review, user=self.user)
        reply_comment = self.create_diff_comment(
            reply, filediff, reply_to=comment)

        self.apiDelete(get_review_reply_diff_comment_item_url(
            reply, reply_comment.pk))

        comments = Comment.objects.filter(review=reply, reply_to=comment)
        self.assertEqual(comments.count(), 0)