Skip to content
Merged
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
43 changes: 25 additions & 18 deletions backend/submissions/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ def notify_new_cfp_submission(*, submission_id, conference_id, admin_url):
speaker = User.objects.get(id=speaker_id)
user_name = get_name(speaker)

fields = []
if submission.topic:
fields += [
{"type": "mrkdwn", "text": "*Topic*"},
{"type": "plain_text", "text": submission.topic.name},
]
# Slack rejects the whole message if a plain_text field is empty.
if tags:
fields += [
{"type": "mrkdwn", "text": "*Tags*"},
{"type": "plain_text", "text": tags},
]

section = {
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*<{admin_url}|{title.capitalize()}>*\n"
f"*Elevator Pitch*\n{elevator_pitch}",
},
}
if fields:
section["fields"] = fields

slack.send_message(
[
{
Expand All @@ -37,24 +61,7 @@ def notify_new_cfp_submission(*, submission_id, conference_id, admin_url):
},
}
],
[
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*<{admin_url}|{title.capitalize()}>*\n"
f"*Elevator Pitch*\n{elevator_pitch}",
},
"fields": [
{"type": "mrkdwn", "text": "*Tags*"},
{"type": "plain_text", "text": str(tags)},
],
}
]
}
],
[{"blocks": [section]}],
oauth_token=conference.get_slack_oauth_token(),
channel_id=conference.slack_new_proposal_channel_id,
)
Expand Down
51 changes: 44 additions & 7 deletions backend/submissions/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,31 @@
pytestmark = pytest.mark.django_db


def test_handle_new_cfp_submission():
@pytest.mark.parametrize(
"topic_name,tags,expected_fields",
[
(None, [], None),
(
"Web",
[],
[
{"type": "mrkdwn", "text": "*Topic*"},
{"type": "plain_text", "text": "Web"},
],
),
(
"Web",
["python"],
[
{"type": "mrkdwn", "text": "*Topic*"},
{"type": "plain_text", "text": "Web"},
{"type": "mrkdwn", "text": "*Tags*"},
{"type": "plain_text", "text": "python"},
],
),
],
)
def test_handle_new_cfp_submission(topic_name, tags, expected_fields):
user = UserFactory(
full_name="Marco Acierno",
email="marco@placeholder.it",
Expand All @@ -27,11 +51,15 @@ def test_handle_new_cfp_submission():

conference = ConferenceFactory(
slack_new_proposal_channel_id="C123456",
topics=(topic_name,) if topic_name else (),
)

submission = SubmissionFactory(
conference=conference,
speaker=user,
topic=None,
custom_topic=topic_name,
tags=tags,
)

with patch("submissions.tasks.slack") as slack_mock:
Expand All @@ -43,6 +71,9 @@ def test_handle_new_cfp_submission():

slack_mock.send_message.assert_called_once()
assert "Marco Acierno" in str(slack_mock.send_message.mock_calls[0])
attachments = slack_mock.send_message.call_args.args[1]
section = attachments[0]["blocks"][0]
assert section.get("fields") == expected_fields


def test_send_proposal_rejected_email(sent_emails):
Expand All @@ -65,13 +96,16 @@ def test_send_proposal_rejected_email(sent_emails):
# Verify that the correct email template was used and email was sent
emails_sent = sent_emails()
assert emails_sent.count() == 1

sent_email = emails_sent.first()
assert sent_email.email_template.identifier == EmailTemplateIdentifier.proposal_rejected
assert (
sent_email.email_template.identifier
== EmailTemplateIdentifier.proposal_rejected
)
assert sent_email.email_template.conference == submission.conference
assert sent_email.recipient == submission.speaker
assert sent_email.recipient_email == submission.speaker.email

# Verify placeholders were processed correctly
assert sent_email.placeholders["proposal_title"] == "Title"
assert sent_email.placeholders["proposal_type"] == submission.type.name
Expand Down Expand Up @@ -99,13 +133,16 @@ def test_send_proposal_in_waiting_list_email(sent_emails):
# Verify that the correct email template was used and email was sent
emails_sent = sent_emails()
assert emails_sent.count() == 1

sent_email = emails_sent.first()
assert sent_email.email_template.identifier == EmailTemplateIdentifier.proposal_in_waiting_list
assert (
sent_email.email_template.identifier
== EmailTemplateIdentifier.proposal_in_waiting_list
)
assert sent_email.email_template.conference == submission.conference
assert sent_email.recipient == submission.speaker
assert sent_email.recipient_email == submission.speaker.email

# Verify placeholders were processed correctly
assert sent_email.placeholders["proposal_title"] == "Title"
assert sent_email.placeholders["proposal_type"] == submission.type.name
Expand Down
Loading