Пример #1
0
def test_conf(mock_config, mock_taskcluster_config):
    """
    Test mail reporter configuration
    """
    from code_review_bot.report.mail import MailReporter

    # Missing emails conf
    with pytest.raises(AssertionError):
        MailReporter({})

    # Missing emails
    conf = {"emails": []}
    with pytest.raises(AssertionError):
        MailReporter(conf)

    # Valid emails
    conf = {"emails": ["*****@*****.**"]}
    r = MailReporter(conf)
    assert r.emails == ["*****@*****.**"]

    conf = {
        "emails":
        ["*****@*****.**", "*****@*****.**", "*****@*****.**"]
    }
    r = MailReporter(conf)
    assert r.emails == [
        "*****@*****.**", "*****@*****.**", "*****@*****.**"
    ]
Пример #2
0
def test_mail(mock_config, mock_issues, mock_revision, mock_taskcluster_config,
              mock_task):
    """
    Test mail sending through Taskcluster
    """
    from code_review_bot.report.mail import MailReporter
    from code_review_bot.revisions import ImprovementPatch

    def _check_email(request):
        payload = json.loads(request.body)

        assert payload["subject"] in (
            "[test] New Static Analysis Phabricator #42 - PHID-DIFF-test", )
        assert payload["address"] == "*****@*****.**"
        assert payload["template"] == "fullscreen"
        assert payload["content"] == MAIL_CONTENT.format(
            results=mock_config.taskcluster.results_dir)

        return (200, {}, "")  # ack

    # Add mock taskcluster email to check output
    responses.add_callback(
        responses.POST,
        "http://taskcluster.test/api/notify/v1/email",
        callback=_check_email,
    )

    # Publish email
    conf = {"emails": ["*****@*****.**"]}
    r = MailReporter(conf)

    mock_revision.improvement_patches = [
        ImprovementPatch(
            mock_task(ClangTidyTask, "clang-tidy"),
            repr(mock_revision),
            "Some code fixes",
        ),
        ImprovementPatch(
            mock_task(ClangFormatTask, "clang-format"),
            repr(mock_revision),
            "Some lint fixes",
        ),
    ]
    list(map(lambda p: p.write(),
             mock_revision.improvement_patches))  # trigger local write
    r.publish(mock_issues, mock_revision, [])

    # Check stats
    assert r.calc_stats(mock_issues) == [{
        "analyzer":
        "mock-analyzer",
        "help":
        None,
        "total":
        5,
        "publishable":
        3,
        "publishable_paths": ["/path/to/file"],
    }]