Exemplo n.º 1
0
def send_landing_failure_email(recipient_email: str, revision_id: str, error_msg: str):
    """Tell a user that the Transplant service couldn't land their code.

    Args:
        recipient_email: The email of the user receiving the failure notification.
        revision_id: The Phabricator Revision ID that failed to land. e.g. D12345
        error_msg: The error message returned by the Transplant service.
    """
    if smtp.suppressed:
        logger.warning(
            f"Email sending suppressed: application config has disabled "
            f"all mail sending (recipient was: {recipient_email})"
        )
        return

    if not smtp.recipient_allowed(recipient_email):
        logger.info(
            f"Email sending suppressed: recipient {recipient_email} not whitelisted"
        )
        return

    with smtp.connection() as c:
        c.send_message(
            make_failure_email(
                smtp.default_from,
                recipient_email,
                revision_id,
                error_msg,
                current_app.config["LANDO_UI_URL"],
            )
        )

    logger.info(f"Notification email sent to {recipient_email}")
Exemplo n.º 2
0
def test_email_content():
    email = make_failure_email(
        "*****@*****.**",
        "*****@*****.**",
        "D54321",
        "Rebase failed!",
        "https://lando.test",
    )
    assert email["To"] == "*****@*****.**"
    assert email["Subject"] == "Lando: Landing of D54321 failed!"
    expected_body = dedent("""
        Your request to land D54321 failed.

        See https://lando.test/D54321/ for details.

        Reason:
        Rebase failed!
        """

                           # noqa
                           )
    assert email.get_content() == expected_body + "\n"