Esempio n. 1
0
    def test_it_returns_only_payments_with_current_status_as_pending(self):
        # given
        user = create_user()
        booking = create_booking(user=user)
        offerer = create_offerer()
        payments = [
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.PENDING),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.NOT_PROCESSABLE),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.ERROR),
        ]

        # when
        pending_payments = keep_only_pending_payments(payments)

        # then
        assert len(pending_payments) == 1
        assert pending_payments[
            0].currentStatus.status == TransactionStatus.PENDING
Esempio n. 2
0
def generate_new_payments() -> Tuple[List[Payment], List[Payment]]:
    offerers = Offerer.query.all()
    all_payments = []

    for offerer in offerers:
        booking_reimbursements = []
        for venue in offerer.managedVenues:
            final_bookings = booking_repository.find_bookings_eligible_for_payment_for_venue(
                venue.id)
            booking_reimbursements += find_all_booking_reimbursements(
                final_bookings, RULES)

        booking_reimbursements_to_pay = filter_out_already_paid_for_bookings(
            filter_out_bookings_without_cost(booking_reimbursements))

        with db.session.no_autoflush:
            payments = list(
                map(create_payment_for_booking, booking_reimbursements_to_pay))

        if payments:
            repository.save(*payments)
            all_payments.extend(payments)
        logger.info("[BATCH][PAYMENTS] Saved %i payments for offerer : %s",
                    len(payments), offerer.name)

    logger.info(
        "[BATCH][PAYMENTS] Generated %i payments for %i offerers in total",
        len(all_payments), len(offerers))

    pending_payments = keep_only_pending_payments(all_payments)
    not_processable_payments = keep_only_not_processable_payments(all_payments)
    logger.info("[BATCH][PAYMENTS] %s Payments in status PENDING to send",
                len(pending_payments))
    return pending_payments, not_processable_payments
Esempio n. 3
0
    def test_it_returns_an_empty_list_if_everything_has_no_pending_payment(
            self):
        # given
        user = create_user()
        booking = create_booking(user=user)
        offerer = create_offerer()
        payments = [
            create_payment(booking, offerer, 30,
                           status=TransactionStatus.SENT),
            create_payment(booking, offerer, 30,
                           status=TransactionStatus.SENT),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.ERROR),
        ]

        # when
        pending_payments = keep_only_pending_payments(payments)

        # then
        assert pending_payments == []
Esempio n. 4
0
    def test_it_returns_an_empty_list_if_an_empty_list_is_given(self):
        # when
        pending_payments = keep_only_pending_payments([])

        # then
        assert pending_payments == []