Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/apps/competitions/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ def send_participation_requested_emails(participant):
'user': participant.user
}
# Notify Organizers
codalab_send_mail(
context_data=context,
subject=f'{participant.user.username} applied to your competition',
html_file="emails/participation/organizer/participation_requested.html",
text_file="emails/participation/organizer/participation_requested.txt",
to_email=get_organizer_emails(participant.competition)
)
for organizer in participant.competition.all_organizers:
if organizer.is_deleted:
continue
codalab_send_mail(
context_data={**context, 'user': organizer},
subject=f'{participant.user.username} applied to your competition',
html_file="emails/participation/organizer/participation_requested.html",
text_file="emails/participation/organizer/participation_requested.txt",
to_email=organizer.email
)

# Notify User
codalab_send_mail(
Expand Down
33 changes: 33 additions & 0 deletions src/apps/competitions/tests/test_emails.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from types import SimpleNamespace
from unittest import mock

from competitions.emails import send_participation_requested_emails


def test_participation_request_uses_each_recipient_as_email_user():
participant_user = SimpleNamespace(
username='participant', email='participant@example.com', is_deleted=False
)
organizers = [
SimpleNamespace(username='owner', email='owner@example.com', is_deleted=False),
SimpleNamespace(username='collaborator', email='collaborator@example.com', is_deleted=False),
SimpleNamespace(username='deleted', email='deleted@example.com', is_deleted=True),
]
participant = SimpleNamespace(
user=participant_user,
competition=SimpleNamespace(title='Competition', all_organizers=organizers),
)

with mock.patch('competitions.emails.codalab_send_mail') as send_mail:
send_participation_requested_emails(participant)

assert [call.kwargs['to_email'] for call in send_mail.call_args_list] == [
'owner@example.com',
'collaborator@example.com',
'participant@example.com',
]
assert [call.kwargs['context_data']['user'] for call in send_mail.call_args_list] == [
organizers[0],
organizers[1],
participant_user,
]