Exemplo n.º 1
0
def test_pr_checker_get_bots_pr_reviews_comment_reviews():
    # Arrange
    args = _get_args()
    pr = MagicMock()
    _setup_pr_reviews(pr, with_comment_body=args.required_label_message)

    pr_checker = PrChecker(args, pr)

    # Act
    bots_prs = pr_checker._get_bots_pr_reviews()

    # Asset
    assert len(bots_prs) == 0
Exemplo n.º 2
0
def test_pr_checker_get_bots_pr_reviews_no_reviews():
    # Arrange
    args = _get_args()
    pr = MagicMock()
    _setup_pr_reviews(pr)

    pr_checker = PrChecker(args, pr)

    # Act
    bots_prs = pr_checker._get_bots_pr_reviews()

    # Asset
    assert len(bots_prs) == 0
Exemplo n.º 3
0
def test_pr_checker_verify_pr_no_critical_file_changes_no_changes_requested():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB], valid_labels=['label1'])
    pr = MagicMock()
    pr.get_files.return_value = [*_get_files()]
    _setup_labels(pr)
    _setup_pr_reviews(pr, with_comment_body=args.changes_reverted_message)

    pr_checker = PrChecker(args, pr)

    # Act
    pr_checker.verify_pr()

    # Asset
    pr.create_review.assert_not_called()
Exemplo n.º 4
0
def test_pr_checker_verify_pr_critical_file_changes_with_label_no_changes_requested():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB], valid_labels=['label1'])
    pr = MagicMock()
    pr.get_files.return_value = [
        *_get_files(),
        MagicMock(filename=CRITICAL_FILE_CHANGE)
    ]
    _setup_labels(pr)
    _setup_pr_reviews(pr)

    pr_checker = PrChecker(args, pr)

    # Act
    pr_checker.verify_pr()

    # Asset
    pr.create_review.assert_not_called()
Exemplo n.º 5
0
def test_pr_checker_no_valid_labels():
    # Arrange
    args = _get_args(valid_labels=['label6', 'label7'])
    pr = MagicMock()
    _setup_labels(pr)

    pr_checker = PrChecker(args, pr)

    # Act and Assert
    assert not pr_checker._pr_has_required_label
Exemplo n.º 6
0
def test_pr_checker_has_not_changed_critical_files():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB])
    pr = MagicMock()
    pr.get_files.return_value = [*_get_files()]

    pr_checker = PrChecker(args, pr)

    # Act and Assert
    assert not pr_checker._pr_has_changed_critical_files
Exemplo n.º 7
0
def test_pr_checker_has_changed_critical_files():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB])
    pr = MagicMock()
    pr.get_files.return_value = [
        *_get_files(),
        MagicMock(filename=CRITICAL_FILE_CHANGE)
    ]

    pr_checker = PrChecker(args, pr)

    # Act and Assert
    assert pr_checker._pr_has_changed_critical_files
Exemplo n.º 8
0
def test_pr_checker_verify_pr_critical_file_changes_no_label():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB], valid_labels=['not_present'])
    pr = MagicMock()
    pr.get_files.return_value = [
        *_get_files(),
        MagicMock(filename=CRITICAL_FILE_CHANGE)
    ]
    _setup_labels(pr)
    _setup_pr_reviews(pr)

    pr_checker = PrChecker(args, pr)

    # Act
    pr_checker.verify_pr()

    # Asset
    pr.create_review.assert_called_once_with(body=f'{args.required_label_message} '
                                             f'Please add one of the following '
                                             f'labels: `{args.valid_labels}` '
                                             'to confirm these changes.',
                                             event='REQUEST_CHANGES')
Exemplo n.º 9
0
def test_pr_checker_has_changed_critical_files_multiple_globs():
    # Arrange
    args = _get_args(file_globs=[DEFAULT_GLOB, 'lib/critical/**/*'])
    pr = MagicMock()
    pr.get_files.return_value = [
        *_get_files(),
        MagicMock(filename='lib/critical/example.py')
    ]

    pr_checker = PrChecker(args, pr)

    # Act and Assert
    assert not pr_checker._pr_has_changed_critical_files