예제 #1
0
def test_send_wallet_balances_does_not_send_anything_if_recipients_are_missing():
    # when
    with pytest.raises(Exception):
        send_wallet_balances(None)

    # then
    assert not mails_testing.outbox
예제 #2
0
def test_send_wallet_balances_does_not_send_anything_if_recipients_are_missing(
        app):
    # when
    with pytest.raises(Exception):
        send_wallet_balances(None)

    # then
    app.mailjet_client.send.create.assert_not_called()
예제 #3
0
def test_send_wallet_balances_sends_a_csv_attachment():
    # when
    send_wallet_balances(["*****@*****.**"])

    # then
    assert len(mails_testing.outbox) == 1
    assert len(mails_testing.outbox[0].sent_data["Attachments"]) == 1
    assert mails_testing.outbox[0].sent_data["Attachments"][0]["ContentType"] == "application/zip"
예제 #4
0
def test_send_wallet_balances_sends_a_csv_attachment(app):
    # given
    app.mailjet_client.send.create.return_value = Mock(status_code=200)

    # when
    send_wallet_balances(["*****@*****.**"])

    # then
    app.mailjet_client.send.create.assert_called_once()
    args = app.mailjet_client.send.create.call_args
    assert len(args[1]["data"]["Attachments"]) == 1
    assert args[1]["data"]["Attachments"][0]["ContentType"] == "text/csv"
예제 #5
0
def generate_and_send_payments(cutoff_date: datetime.datetime, batch_date: datetime.datetime = None):
    logger.info("[BATCH][PAYMENTS] STEP 0 : validate bookings associated to outdated stocks")
    if FeatureToggle.UPDATE_BOOKING_USED.is_active():
        bookings_api.auto_mark_as_used_after_event()

    if batch_date is None:
        batch_date = datetime.datetime.utcnow()
        generate_payments(cutoff_date, batch_date)

    payments_to_send = payment_queries.get_payments_by_status(
        (TransactionStatus.PENDING, TransactionStatus.ERROR, TransactionStatus.RETRY), batch_date
    )

    logger.info("[BATCH][PAYMENTS] STEP 3 : send transactions")
    send_transactions(
        payments_to_send,
        batch_date,
        settings.PASS_CULTURE_IBAN,
        settings.PASS_CULTURE_BIC,
        settings.PASS_CULTURE_REMITTANCE_CODE,
        settings.TRANSACTIONS_RECIPIENTS,
    )
    # `send_transactions()` updates the status of the payments. Thus,
    # `payments_to_send` must not be used anymore since the query
    # would not yield any result anymore.
    del payments_to_send

    logger.info("[BATCH][PAYMENTS] STEP 4 : send payments report")
    send_payments_report(batch_date, settings.PAYMENTS_REPORT_RECIPIENTS)

    # Recreate `payments_to_send` query, after `send_transactions()`
    # has updated the status of all payments.
    payments_to_send = payment_queries.get_payments_by_status([TransactionStatus.UNDER_REVIEW], batch_date)
    logger.info("[BATCH][PAYMENTS] STEP 5 : send payments details")
    send_payments_details(payments_to_send, settings.PAYMENTS_DETAILS_RECIPIENTS)

    # This is the only place where we want to catch errors, since it's
    # not really related to payment data (and can easily be executed
    # manually).
    try:
        logger.info("[BATCH][PAYMENTS] STEP 6 : send wallet balances")
        send_wallet_balances(settings.WALLET_BALANCES_RECIPIENTS)
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("[BATCH][PAYMENTS] STEP 6: %s", e)

    logger.info("[BATCH][PAYMENTS] generate_and_send_payments is done")
예제 #6
0
def generate_and_send_payments(payment_message_id: str = None):
    logger.info(
        "[BATCH][PAYMENTS] STEP 0 : validate bookings associated to outdated stocks"
    )
    if feature_queries.is_active(FeatureToggle.UPDATE_BOOKING_USED):
        update_booking_used_after_stock_occurrence()

    not_processable_payments, payments_to_send = generate_or_collect_payments(
        payment_message_id)

    try:
        logger.info("[BATCH][PAYMENTS] STEP 3 : send transactions")
        send_transactions(
            payments_to_send,
            settings.PASS_CULTURE_IBAN,
            settings.PASS_CULTURE_BIC,
            settings.PASS_CULTURE_REMITTANCE_CODE,
            settings.TRANSACTIONS_RECIPIENTS,
        )
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("[BATCH][PAYMENTS] STEP 3: %s", e)

    try:
        logger.info("[BATCH][PAYMENTS] STEP 4 : send payments report")
        send_payments_report(payments_to_send + not_processable_payments,
                             settings.PAYMENTS_REPORT_RECIPIENTS)
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("[BATCH][PAYMENTS] STEP 4: %s", e)

    try:
        logger.info("[BATCH][PAYMENTS] STEP 5 : send payments details")
        send_payments_details(payments_to_send,
                              settings.PAYMENTS_DETAILS_RECIPIENTS)
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("[BATCH][PAYMENTS] STEP 5: %s", e)

    try:
        logger.info("[BATCH][PAYMENTS] STEP 6 : send wallet balances")
        send_wallet_balances(settings.WALLET_BALANCES_RECIPIENTS)
    except Exception as e:  # pylint: disable=broad-except
        logger.exception("[BATCH][PAYMENTS] STEP 6: %s", e)

    logger.info("[BATCH][PAYMENTS] generate_and_send_payments is done")