def should_notify_of_todays_expired_bookings(self, mocked_send_email_recap, mocked_send_raw_email, app, caplog) -> None: caplog.set_level(logging.INFO) now = datetime.utcnow() yesterday = now - timedelta(days=1) long_ago = now - timedelta(days=31) very_long_ago = now - timedelta(days=32) dvd = ProductFactory(type=str(offer_type.ThingType.AUDIOVISUEL)) expired_today_dvd_booking = BookingFactory( stock__offer__product=dvd, dateCreated=long_ago, isCancelled=True, cancellationReason=BookingCancellationReasons.EXPIRED, ) cd = ProductFactory(type=str(offer_type.ThingType.MUSIQUE)) expired_today_cd_booking = BookingFactory( stock__offer__product=cd, dateCreated=long_ago, isCancelled=True, cancellationReason=BookingCancellationReasons.EXPIRED, ) painting = ProductFactory(type=str(offer_type.ThingType.OEUVRE_ART)) expired_yesterday_painting_booking = BookingFactory( stock__offer__product=painting, dateCreated=very_long_ago, isCancelled=True, cancellationReason=BookingCancellationReasons.EXPIRED, ) expired_yesterday_painting_booking.cancellationDate = yesterday repository.save(expired_yesterday_painting_booking) handle_expired_bookings.notify_offerers_of_expired_bookings() assert ( caplog.records[1].message == f"[notify_users_of_expired_bookings] 2 Offerers have been notified: [{expired_today_dvd_booking.stock.offer.venue.managingOfferer}," f" {expired_today_cd_booking.stock.offer.venue.managingOfferer}]") assert str(expired_yesterday_painting_booking) not in caplog.text assert mocked_send_email_recap.call_args_list[0][0] == ( expired_today_dvd_booking.stock.offer.venue.managingOfferer, [expired_today_dvd_booking], mocked_send_raw_email, ) assert mocked_send_email_recap.call_args_list[1][0] == ( expired_today_cd_booking.stock.offer.venue.managingOfferer, [expired_today_cd_booking], mocked_send_raw_email, )
def should_not_update_cancelled_old_thing_that_can_expire_booking( self, app) -> None: fifty_days_ago = datetime.utcnow() - timedelta(days=50) forty_days_ago = datetime.utcnow() - timedelta(days=40) book = ProductFactory(type=str(offer_type.ThingType.LIVRE_EDITION)) old_book_booking = BookingFactory( stock__offer__product=book, dateCreated=fifty_days_ago, isCancelled=True, cancellationReason=BookingCancellationReasons.BENEFICIARY, ) old_book_booking.cancellationDate = forty_days_ago repository.save() handle_expired_bookings.cancel_expired_bookings() assert old_book_booking.isCancelled assert old_book_booking.cancellationDate == forty_days_ago assert old_book_booking.cancellationReason == BookingCancellationReasons.BENEFICIARY