diff --git a/api/src/pcapi/workers/push_notification_job.py b/api/src/pcapi/workers/push_notification_job.py index 98db62fcbee..85467db223b 100644 --- a/api/src/pcapi/workers/push_notification_job.py +++ b/api/src/pcapi/workers/push_notification_job.py @@ -21,6 +21,9 @@ def send_cancel_booking_notification(bookings_ids: list[int]) -> None: send_transactional_notification(notification_data) +OFFER_IDS_TO_NOT_NOTIFY = [232581516] + + @job(worker.default_queue) def send_today_stock_notification(stock_id: int) -> None: """ @@ -32,6 +35,8 @@ def send_today_stock_notification(stock_id: int) -> None: bookings = bookings_api.get_individual_bookings_from_stock(stock_id) for booking in bookings: + if offer.id in OFFER_IDS_TO_NOT_NOTIFY: + continue notification_data = get_today_stock_booking_notification_data(booking, offer) if notification_data: send_transactional_notification(notification_data) diff --git a/api/tests/core/bookings/external/test_booking_notifications.py b/api/tests/core/bookings/external/test_booking_notifications.py index 4c9a57ae9a3..a22e68684cb 100644 --- a/api/tests/core/bookings/external/test_booking_notifications.py +++ b/api/tests/core/bookings/external/test_booking_notifications.py @@ -13,6 +13,7 @@ from pcapi.core.testing import override_settings from pcapi.core.users import factories as users_factories from pcapi.notifications.push import testing +from pcapi.workers.push_notification_job import OFFER_IDS_TO_NOT_NOTIFY @pytest.mark.usefixtures("db_session") @@ -53,6 +54,22 @@ def test_send_today_events_notifications_only_to_individual_bookings_users(): assert user_ids == {user1.id, user2.id} +@pytest.mark.usefixtures("db_session") +# Set time to evening so that `send_today_events_notifications_metropolitan_france()` +# finds test stock in its `13:00 - 24:00` window. +@time_machine.travel("20:00:00") +def test_do_not_send_notifications_to_banned_offers(): + in_one_hour = datetime.utcnow() + timedelta(hours=1) + stock_today = offers_factories.EventStockFactory( + beginningDatetime=in_one_hour, offer__id=OFFER_IDS_TO_NOT_NOTIFY[0], offer__name="my_offer" + ) + bookings_factories.BookingFactory(stock=stock_today) + + send_today_events_notifications_metropolitan_france() + + assert len(testing.requests) == 0 + + @pytest.mark.usefixtures("db_session") @override_settings(SOON_EXPIRING_BOOKINGS_DAYS_BEFORE_EXPIRATION=3) def test_notify_users_bookings_not_retrieved() -> None: