コード例 #1
0
ファイル: tasks.py プロジェクト: islahudinees/invenio-app-ils
def send_loan_mail(action,
                   loan,
                   is_manually_triggered=False,
                   message_ctx={},
                   **kwargs):
    """Send loan email message asynchronously and log the result in Celery.

    :param action: the triggered loan action.
    :param loan: the loan record.
    :param message_ctx: any other parameter to be passed as ctx in the msg.
    """
    creator = loan_message_creator_factory()

    message_ctx.update(get_common_message_ctx(record=loan))
    message_ctx["circulation_delivery_methods"] = current_app.config[
        "ILS_CIRCULATION_DELIVERY_METHODS"]
    patron = message_ctx["patron"]

    msg = creator(
        loan,
        action=action,
        message_ctx=message_ctx,
        recipients=[patron.email],
        **kwargs,
    )
    send_ils_email(msg, is_manually_triggered)
コード例 #2
0
ファイル: test_mails.py プロジェクト: topless/invenio-app-ils
def test_log_successful_error_mail_task(app_with_mail, mocker):
    """Test that a successfully sent email is logged."""
    succ = mocker.patch("invenio_app_ils.mail.tasks.log_successful_mail")
    err = mocker.patch("invenio_app_ils.mail.tasks.log_error_mail")

    assert not succ.s.called
    assert not err.s.called
    send_ils_email(TestMessage())
    assert succ.s.called
    assert err.s.called
コード例 #3
0
ファイル: test_mails.py プロジェクト: topless/invenio-app-ils
def test_send_only_to_test_recipients(app_with_mail, mocker):
    """Tests that send only to test recipients works."""
    app_with_mail.config["ILS_MAIL_ENABLE_TEST_RECIPIENTS"] = True

    msg = TestMessage(recipients=["*****@*****.**"])

    fake_recipients = app_with_mail.config["ILS_MAIL_NOTIFY_TEST_RECIPIENTS"]
    with app_with_mail.extensions["mail"].record_messages() as outbox:
        assert len(outbox) == 0
        send_ils_email(msg)
        assert len(outbox) == 1
        assert outbox[0].recipients == fake_recipients

    app_with_mail.config["ILS_MAIL_ENABLE_TEST_RECIPIENTS"] = False
コード例 #4
0
ファイル: tasks.py プロジェクト: topless/invenio-app-ils
def send_document_request_mail(request, action=None, message_ctx={}, **kwargs):
    """Send a document request email.

    :param request: the document request record.
    :param action: the action performed, if any.
    :param message_ctx: any other parameter to be passed as ctx in the msg.
    """
    creator = document_request_message_creator_factory()

    message_ctx.update(get_common_message_ctx(record=request))
    patron = message_ctx["patron"]

    msg = creator(
        request,
        action=action,
        message_ctx=message_ctx,
        recipients=[patron.email],
        **kwargs,
    )
    send_ils_email(msg)
コード例 #5
0
ファイル: tasks.py プロジェクト: topless/invenio-app-ils
def send_loan_mail(action, loan, message_ctx={}, **kwargs):
    """Send loan email message asynchronously and log the result in Celery.

    :param action: the triggered loan action.
    :param loan: the loan record.
    :param message_ctx: any other parameter to be passed as ctx in the msg.
    """
    creator = loan_message_creator_factory()

    message_ctx.update(get_common_message_ctx(record=loan))
    patron = message_ctx["patron"]

    msg = creator(
        loan,
        action=action,
        message_ctx=message_ctx,
        recipients=[patron.email],
        **kwargs,
    )
    send_ils_email(msg)
コード例 #6
0
ファイル: tasks.py プロジェクト: mvidalgarcia/invenio-app-ils
def send_loan_mail(trigger, loan, message_ctx={}, **kwargs):
    """Send loan email message asynchronously and log the result in Celery.

    :param trigger: Loan action trigger.
    :param loan: Updated loan.
    :param message_ctx: any other parameter to be passed as ctx in the msg.
    """
    patron = Patron.get_patron(loan["patron_pid"])
    document = Document.get_record_by_pid(loan["document_pid"])
    factory = loan_message_factory()
    msg = factory(
        trigger,
        message_ctx=dict(
            loan=loan,
            document=dict(title=document["title"]),
            patron=patron,
            **message_ctx,
        ),
        recipients=get_recipients([patron.email]),
        **kwargs,
    )
    send_ils_email(msg)