Example #1
0
    def create_diff_comment(self, review, filediff, interfilediff=None,
                            text='My comment', issue_opened=False,
                            issue_status=None,
                            first_line=1, num_lines=5, extra_fields=None,
                            reply_to=None, **kwargs):
        """Creates a Comment for testing.

        The comment is tied to the given Review and FileDiff (and, optionally,
        an interfilediff). It's populated with default data that can be
        overridden by the caller.
        """
        if issue_opened and not issue_status:
            issue_status = Comment.OPEN

        comment = Comment(
            filediff=filediff,
            interfilediff=interfilediff,
            first_line=first_line,
            num_lines=num_lines,
            text=text,
            issue_opened=issue_opened,
            issue_status=issue_status,
            reply_to=reply_to,
            **kwargs)

        if extra_fields:
            comment.extra_data = extra_fields

        comment.save()
        review.comments.add(comment)

        return comment
Example #2
0
    def test_spanning_last_chunk(self):
        """Testing diff_comment_line_numbers with spanning chunks through last
        chunk
        """
        t = Template('{% load reviewtags %}'
                     '{% diff_comment_line_numbers chunks comment %}')

        result = t.render(
            Context({
                'comment':
                Comment(first_line=20, num_lines=50),
                'chunks': [
                    {
                        'change':
                        'delete',
                        'lines': [
                            (10, 20, 'deleted line', [], '', '', [], False),
                            # ...
                            (50, 60, 'deleted line', [], '', '', [], False),
                        ],
                    },
                    {
                        'change':
                        'insert',
                        'lines': [
                            (51, '', '', [], 61, 'inserted line', [], False),
                            # ...
                            (100, '', '', [], 110, 'inserted line', [], False),
                        ],
                    },
                ],
            }))

        self.assertEqual(result, 'Lines 30-60 (original), 61-79 (patched)')
Example #3
0
    def test_fake_equal_patched(self):
        """Testing diff_comment_line_numbers with fake equal from patched
        side of interdiff
        """
        t = Template('{% load reviewtags %}'
                     '{% diff_comment_line_numbers chunks comment %}')

        result = t.render(
            Context({
                'comment':
                Comment(first_line=20, num_lines=2),
                'chunks': [
                    {
                        'change':
                        'equal',
                        'lines': [
                            (10, 20, 'deleted line', [], '', '', [], False),
                            # ...
                            (50, 60, 'deleted line', [], '', '', [], False),
                        ],
                    },
                ],
            }))

        self.assertEqual(result, 'Lines 30-31 (original)')
Example #4
0
    def test_insert_multiple_lines(self):
        """Testing diff_comment_line_numbers with insert chunk and multiple
        commented lines
        """
        t = Template('{% load reviewtags %}'
                     '{% diff_comment_line_numbers chunks comment %}')

        result = t.render(
            Context({
                'comment':
                Comment(first_line=20, num_lines=2),
                'chunks': [
                    {
                        'change':
                        'insert',
                        'lines': [
                            (10, '', '', [], 20, 'inserted line', [], False),
                            # ...
                            (50, '', '', [], 60, 'inserted line', [], False),
                        ],
                    },
                ],
            }))

        self.assertEqual(result, 'Lines 30-31 (patched)')
Example #5
0
    def test_replace_single_line(self):
        """Testing diff_comment_line_numbers with replace chunk and single
        commented line
        """
        t = Template('{% load reviewtags %}'
                     '{% diff_comment_line_numbers chunks comment %}')

        result = t.render(
            Context({
                'comment':
                Comment(first_line=20, num_lines=1),
                'chunks': [
                    {
                        'change':
                        'replace',
                        'lines': [
                            (10, 20, 'foo', [], 20, 'replaced line', [],
                             False),
                            # ...
                            (50, 60, 'foo', [], 60, 'replaced line', [], False
                             ),
                        ],
                    },
                ],
            }))

        self.assertEqual(result, 'Line 30 (original), 30 (patched)')
Example #6
0
    def create_diff_comment(self,
                            review,
                            filediff,
                            interfilediff=None,
                            text='My comment',
                            issue_opened=False,
                            issue_status=None,
                            first_line=1,
                            num_lines=5,
                            extra_fields=None,
                            reply_to=None,
                            **kwargs):
        """Create a Comment for testing.

        The comment is tied to the given Review and FileDiff (and, optionally,
        an interfilediff). It's populated with default data that can be
        overridden by the caller.

        Args:
            review (reviewboard.reviews.models.review.Review):
                The review associated with the comment.

            filediff (reviewboard.diffviewer.models.FileDiff):
                The FileDiff associated with the comment.

            interfilediff (reviewboard.diffviewer.models.FileDiff, optional):
                The FileDiff used for the end of an interdiff range associated
                with the comment.

            text (unicode):
                The text for the comment.

            issue_opened (bool, optional):
                Whether an issue is to be opened for the comment.

            issue_status (unicode, optional):
                The issue status to set, if an issue is opened. Defaults to
                being an open issue.

            first_line (int, optional):
                The first line (0-based) of the comment range.

            num_lines (int, optional):
                The number of lines in the comment.

            extra_fields (dict, optional):
                Extra data to set on the comment.

            reply_to (reviewboard.reviews.models.diff_comment.Comment,
                      optional):
                The comment this comment replies to.

            **kwargs (dict):
                Additional model attributes to set on the comment.

        Returns:
            reviewboard.reviews.models.diff_comment.Comment:
            The resulting comment.
        """
        if issue_opened and not issue_status:
            issue_status = Comment.OPEN

        comment = Comment(filediff=filediff,
                          interfilediff=interfilediff,
                          first_line=first_line,
                          num_lines=num_lines,
                          text=text,
                          issue_opened=issue_opened,
                          issue_status=issue_status,
                          reply_to=reply_to,
                          **kwargs)

        if extra_fields:
            comment.extra_data = extra_fields

        comment.save()
        review.comments.add(comment)

        return comment