Пример #1
0
def test_send_report_default(context, mocker, fixture_dir, empty_config, smtp):
    """Should use default SMTP and email values if they are not set in the config."""
    report.send_report(**context)

    smtp.assert_called_once_with(report.DEFAULT_SMTP_SERVER)
    assert smtp.get_sent_message()["From"] == report.DEFAULT_SENDER
    assert smtp.get_sent_message()["To"] == report.DEFAULT_RECIPIENT
Пример #2
0
def test_send_report_custom_config(context, smtp):
    """Should use values from custom config file."""
    config = dict(alerts_from="*****@*****.**", alerts_to="*****@*****.**", alerts_smtp_server="smtp.example.com")
    report.send_report(context, "", config)

    smtp.assert_called_once_with("smtp.example.com")
    assert smtp.get_sent_message()["From"] == "*****@*****.**"
    assert smtp.get_sent_message()["To"] == "*****@*****.**"
Пример #3
0
def test_send_report_custom_config(context, mocker, fixture_dir, smtp):
    """Should use values from custom config file."""
    report.send_report(**context,
                       config_file=fixture_dir / "general_section_only.ini")

    smtp.assert_called_once_with("smtp.example.com")
    assert smtp.get_sent_message()["From"] == "*****@*****.**"
    assert smtp.get_sent_message()["To"] == "*****@*****.**"
Пример #4
0
def test_send_report(context, mocker, fixture_dir, smtp):
    """Should send full message report."""
    render = mocker.spy(report, "render_from_template")
    report.send_report(**context,
                       config_file=fixture_dir / "sample_config.ini")

    assert render.call_count == 2
    smtp.assert_called_once_with("smtp.corp.redhat.com")

    for p in smtp.get_sent_message().iter_parts():
        content = p.get_content()
        assert all([v in content for v in context.values()])
Пример #5
0
def test_send_report_default(context, mocker, smtp):
    """Should use default SMTP and email values if they are not set in the config."""
    render = mocker.spy(report, "render_from_template")
    report.send_report(context, "", {})

    assert render.call_count == 2
    smtp.assert_called_once_with(report.DEFAULT_SMTP_SERVER)
    assert smtp.get_sent_message()["From"] == report.DEFAULT_SENDER
    assert smtp.get_sent_message()["To"] == report.DEFAULT_RECIPIENT

    for p in smtp.get_sent_message().iter_parts():
        content = p.get_content()
        assert all([v in content for v in context.values()])
Пример #6
0
def test_send_report_with_failures(context, empty_config, smtp):
    """Should render failures."""
    failure = {
        "displayName": "failed-step-name",
        "message": "failed with exit code 1",
        "templateName": "template_x_y_z",
        "podName": "failed-step-name-pod-123456",
        "phase": "Failed",
        "finishedAt": "2020-01-01 10:00:00 +0000 UTC",
    }
    context["failures"] = dumps([failure])
    report.send_report(**context)

    for p in smtp.get_sent_message().iter_parts():
        content = p.get_content()
        assert "Failures:" in content
        assert all([v in content for v in failure.values()])
Пример #7
0
def test_send_report_no_context(smtp):
    """Should fail to send empty message."""
    with pytest.raises(ValueError):
        report.send_report({}, "", {})
Пример #8
0
def test_send_report_no_context(empty_config, smtp):
    """Should fail to send empty message."""
    with pytest.raises(SystemExit):
        report.send_report("", "", "", "", "", "")