def test_do_not_update_if_thing_product(self): booking_factories.IndividualBookingFactory(stock=offers_factories.ThingStockFactory()) api.auto_mark_as_used_after_event() booking = Booking.query.first() assert not booking.isUsed assert booking.status is not BookingStatus.USED assert not booking.dateUsed
def test_does_not_update_booking_if_already_used(self): event_date = datetime.now() - timedelta(days=3) booking = booking_factories.UsedIndividualBookingFactory(stock__beginningDatetime=event_date) initial_date_used = booking.dateUsed api.auto_mark_as_used_after_event() booking = Booking.query.first() assert booking.isUsed assert booking.dateUsed == initial_date_used
def test_does_not_update_when_event_date_is_only_1_day_before(self): event_date = datetime.now() - timedelta(days=1) booking_factories.IndividualBookingFactory(stock__beginningDatetime=event_date) api.auto_mark_as_used_after_event() booking = Booking.query.first() assert not booking.isUsed assert booking.status is not BookingStatus.USED assert booking.dateUsed is None
def test_update_booking_used_when_event_date_is_3_days_before(self): event_date = datetime.now() - timedelta(days=3) booking_factories.IndividualBookingFactory(stock__beginningDatetime=event_date) api.auto_mark_as_used_after_event() booking = Booking.query.first() assert booking.isUsed assert booking.status is BookingStatus.USED assert booking.dateUsed == datetime(2021, 1, 1)
def test_update_educational_booking_if_not_used_and_not_validated_by_principal_yet(self): event_date = datetime.now() - timedelta(days=3) booking_factories.EducationalBookingFactory( stock__beginningDatetime=event_date, educationalBooking__status=None, ) api.auto_mark_as_used_after_event() non_validated_by_ce_educational_booking = Booking.query.first() assert non_validated_by_ce_educational_booking.isUsed assert non_validated_by_ce_educational_booking.status is BookingStatus.USED
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")
def test_raise_if_feature_flag_is_deactivated(self): with pytest.raises(ValueError): api.auto_mark_as_used_after_event()
def update_booking_used() -> None: bookings_api.auto_mark_as_used_after_event()