Skip to content

Commit

Permalink
(PC-31077)[API] feat: disable today push notification for a specific …
Browse files Browse the repository at this point in the history
…offer

This offer is linked to the Olympic games. There are a lot of
beneficiaries that have not received their ticket to the event, but we
can't help them, only the Olympic staff can.
  • Loading branch information
cepehang committed Jul 25, 2024
1 parent 08d1127 commit a868459
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/src/pcapi/workers/push_notification_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions api/tests/core/bookings/external/test_booking_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit a868459

Please sign in to comment.