Skip to content

Commit

Permalink
refactor(notification): nom plus spécifique pour les notifications de…
Browse files Browse the repository at this point in the history
…s messages
  • Loading branch information
calummackervoy committed Jul 2, 2024
1 parent 488c8f2 commit 59d335e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion clevercloud/send_notifications_daily.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fi
# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

python manage.py send_notifications day
python manage.py send_messages_notifications day
2 changes: 1 addition & 1 deletion clevercloud/send_notifications_regular.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ fi
# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

python manage.py send_notifications asap
python manage.py send_messages_notifications asap
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.core.management.base import BaseCommand

from lacommunaute.notification.enums import NotificationDelay
from lacommunaute.notification.tasks import send_notifications
from lacommunaute.notification.tasks import send_messages_notifications


class Command(BaseCommand):
Expand All @@ -18,5 +18,5 @@ def add_arguments(self, parser):
self.style.ERROR(f"le délai fournit doit être un valeuer de {str(NotificationDelay.values)}")
)

send_notifications(delay)
send_messages_notifications(delay)
self.stdout.write(self.style.SUCCESS("That's all, folks!"))
4 changes: 2 additions & 2 deletions lacommunaute/notification/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from lacommunaute.notification.utils import collect_new_users_for_onboarding, get_serialized_messages


def send_notifications(delay: NotificationDelay):
def send_messages_notifications(delay: NotificationDelay):
"""Notifications are scheduled in the application and then processed later by this task"""

def get_grouped_notifications():
Expand All @@ -36,7 +36,7 @@ def get_grouped_notifications():
to=[{"email": DEFAULT_FROM_EMAIL}],
params=params,
bcc=[{"email": recipient}],
kind=EmailSentTrackKind.FIRST_REPLY,
kind=EmailSentTrackKind.FOLLOWING_REPLIES,
template_id=SIB_NEW_MESSAGES_TEMPLATE,
)

Expand Down
20 changes: 10 additions & 10 deletions lacommunaute/notification/tests/tests_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from lacommunaute.notification.models import EmailSentTrack, Notification
from lacommunaute.notification.tasks import (
add_user_to_list_when_register,
send_notifications,
send_messages_notifications,
send_notifs_on_unanswered_topics,
)
from lacommunaute.notification.utils import get_serialized_messages
Expand Down Expand Up @@ -70,11 +70,11 @@ def get_expected_email_payload(self, notifications):
}

@respx.mock
def test_send_notifications_asap(self):
def test_send_messages_notifications_asap(self):
topic = TopicFactory(with_post=True)
notification = NotificationFactory(post=topic.first_post, delay=NotificationDelay.ASAP)

send_notifications(NotificationDelay.ASAP)
send_messages_notifications(NotificationDelay.ASAP)

email_sent_track = EmailSentTrack.objects.get()
self.assertEqual(email_sent_track.status_code, 200)
Expand All @@ -84,11 +84,11 @@ def test_send_notifications_asap(self):
)

@respx.mock
def test_send_notifications_day(self):
def test_send_messages_notifications_day(self):
topic = TopicFactory(with_post=True)
notification = NotificationFactory(post=topic.first_post, delay=NotificationDelay.DAY)

send_notifications(NotificationDelay.DAY)
send_messages_notifications(NotificationDelay.DAY)

email_sent_track = EmailSentTrack.objects.get()
self.assertEqual(email_sent_track.status_code, 200)
Expand All @@ -98,7 +98,7 @@ def test_send_notifications_day(self):
)

@respx.mock
def test_send_notifications_max_messages_preview(self):
def test_send_messages_notifications_max_messages_preview(self):
topic = TopicFactory(with_post=True)
notif_count_to_generate = NEW_MESSAGES_EMAIL_MAX_PREVIEW + 1

Expand All @@ -110,7 +110,7 @@ def test_send_notifications_max_messages_preview(self):
post=topic.first_post,
)

send_notifications(NotificationDelay.ASAP)
send_messages_notifications(NotificationDelay.ASAP)

email_sent_track = EmailSentTrack.objects.get()
self.assertEqual(len(email_sent_track.datas["params"]["messages"]), NEW_MESSAGES_EMAIL_MAX_PREVIEW)
Expand All @@ -120,18 +120,18 @@ def test_send_notifications_max_messages_preview(self):
)

@respx.mock
def test_send_notifications_num_queries(self):
def test_send_messages_notifications_num_queries(self):
expected_queries = 1

NotificationFactory(delay=NotificationDelay.ASAP)

with self.assertNumQueries(expected_queries):
send_notifications(NotificationDelay.ASAP)
send_messages_notifications(NotificationDelay.ASAP)

NotificationFactory.create_batch(10, delay=NotificationDelay.ASAP)

with self.assertNumQueries(expected_queries):
send_notifications(NotificationDelay.ASAP)
send_messages_notifications(NotificationDelay.ASAP)


class AddUserToListWhenRegister(TestCase):
Expand Down

0 comments on commit 59d335e

Please sign in to comment.