def notify_users_of_expired_individual_bookings( expired_on: datetime.date = None) -> None: expired_on = expired_on or datetime.date.today() logger.info("[notify_users_of_expired_bookings] Start") expired_individual_bookings_ordered_by_user = bookings_repository.find_expired_individual_bookings_ordered_by_user( expired_on) expired_bookings_grouped_by_user = dict() for user, individual_bookings in groupby( expired_individual_bookings_ordered_by_user, attrgetter("user")): expired_bookings_grouped_by_user[user] = list(individual_bookings) notified_users = [] for user, individual_bookings in expired_bookings_grouped_by_user.items(): send_expired_bookings_recap_email_to_beneficiary( user, [ individual_booking.booking for individual_booking in individual_bookings ]) notified_users.append(user) logger.info( "[notify_users_of_expired_bookings] %d Users have been notified: %s", len(notified_users), notified_users, ) logger.info("[notify_users_of_expired_bookings] End")
def test_should_send_email_to_beneficiary_when_expired_bookings_cancelled( self, app): amnesiac_user = users_factories.UserFactory(email="*****@*****.**") expired_today_dvd_booking = BookingFactory(user=amnesiac_user, ) expired_today_cd_booking = BookingFactory(user=amnesiac_user, ) send_expired_bookings_recap_email_to_beneficiary( amnesiac_user, [expired_today_cd_booking, expired_today_dvd_booking]) assert mails_testing.outbox[0].sent_data["Mj-TemplateID"] == 1951103
def test_should_send_email_to_beneficiary_when_expired_book_booking_cancelled( self, app): amnesiac_user = users_factories.BeneficiaryGrant18Factory( email="*****@*****.**") expired_today_book_booking = booking_factories.IndividualBookingFactory( user=amnesiac_user, stock__offer__subcategoryId=subcategories.LIVRE_PAPIER.id) send_expired_bookings_recap_email_to_beneficiary( amnesiac_user, [expired_today_book_booking]) assert len(mails_testing.outbox) == 1 assert mails_testing.outbox[0].sent_data["Mj-TemplateID"] == 3095107 assert mails_testing.outbox[0].sent_data["Vars"][ "withdrawal_period"] == 10
def test_should_send_email_to_beneficiary_when_expired_bookings_cancelled( self, app): amnesiac_user = users_factories.UserFactory(email="*****@*****.**") expired_today_dvd_booking = BookingFactory(user=amnesiac_user, ) expired_today_cd_booking = BookingFactory(user=amnesiac_user, ) mocked_send_email = Mock() send_expired_bookings_recap_email_to_beneficiary( amnesiac_user, [expired_today_cd_booking, expired_today_dvd_booking], mocked_send_email) mocked_send_email.assert_called_once() mocked_send_email.call_args_list[0][1]["MJ-TemplateID"] = 1951103