|
1 | 1 | from unittest.mock import call |
| 2 | +from conferences.tests.factories import ConferenceFactory |
| 3 | +from notifications.tests.factories import EmailTemplateFactory |
| 4 | +from notifications.models import EmailTemplateIdentifier, SentEmail |
2 | 5 | import pytest |
3 | 6 | from submissions.admin import ( |
| 7 | + apply_and_notify_status_change, |
4 | 8 | send_proposal_in_waiting_list_email_action, |
5 | 9 | send_proposal_rejected_email_action, |
6 | 10 | ) |
@@ -59,3 +63,84 @@ def test_send_proposal_in_waiting_list_email_action(rf, mocker): |
59 | 63 | ], |
60 | 64 | any_order=True, |
61 | 65 | ) |
| 66 | + |
| 67 | + |
| 68 | +def test_apply_and_notify_status_change(rf, mocker): |
| 69 | + mocker.patch("submissions.admin.messages") |
| 70 | + |
| 71 | + conference = ConferenceFactory() |
| 72 | + proposal_accepted_template = EmailTemplateFactory( |
| 73 | + identifier=EmailTemplateIdentifier.proposal_accepted, |
| 74 | + conference=conference, |
| 75 | + ) |
| 76 | + proposal_rejected_template = EmailTemplateFactory( |
| 77 | + identifier=EmailTemplateIdentifier.proposal_rejected, |
| 78 | + conference=conference, |
| 79 | + ) |
| 80 | + proposal_in_waiting_list_template = EmailTemplateFactory( |
| 81 | + identifier=EmailTemplateIdentifier.proposal_in_waiting_list, |
| 82 | + conference=conference, |
| 83 | + ) |
| 84 | + |
| 85 | + accepted_submission = SubmissionFactory( |
| 86 | + conference=conference, |
| 87 | + status=Submission.STATUS.proposed, |
| 88 | + pending_status=Submission.STATUS.accepted, |
| 89 | + speaker__full_name="Marco", |
| 90 | + ) |
| 91 | + |
| 92 | + rejected_submission = SubmissionFactory( |
| 93 | + conference=conference, |
| 94 | + status=Submission.STATUS.proposed, |
| 95 | + pending_status=Submission.STATUS.rejected, |
| 96 | + speaker__full_name="Jane", |
| 97 | + ) |
| 98 | + |
| 99 | + waiting_list_proposal = SubmissionFactory( |
| 100 | + conference=conference, |
| 101 | + status=Submission.STATUS.proposed, |
| 102 | + pending_status=Submission.STATUS.waiting_list, |
| 103 | + speaker__full_name="John", |
| 104 | + ) |
| 105 | + |
| 106 | + apply_and_notify_status_change( |
| 107 | + None, |
| 108 | + rf.post("/"), |
| 109 | + queryset=Submission.objects.filter(status=Submission.STATUS.proposed), |
| 110 | + ) |
| 111 | + |
| 112 | + assert SentEmail.objects.filter( |
| 113 | + recipient=accepted_submission.speaker, |
| 114 | + email_template=proposal_accepted_template, |
| 115 | + conference=conference, |
| 116 | + placeholders={ |
| 117 | + "conference_name": conference.name.localize("en"), |
| 118 | + "proposal_title": accepted_submission.title.localize("en"), |
| 119 | + "proposal_type": accepted_submission.type.name, |
| 120 | + "speaker_name": "Marco", |
| 121 | + }, |
| 122 | + ).exists() |
| 123 | + |
| 124 | + assert SentEmail.objects.filter( |
| 125 | + recipient=rejected_submission.speaker, |
| 126 | + email_template=proposal_rejected_template, |
| 127 | + conference=conference, |
| 128 | + placeholders={ |
| 129 | + "conference_name": conference.name.localize("en"), |
| 130 | + "proposal_title": rejected_submission.title.localize("en"), |
| 131 | + "proposal_type": rejected_submission.type.name, |
| 132 | + "speaker_name": "Jane", |
| 133 | + }, |
| 134 | + ).exists() |
| 135 | + |
| 136 | + assert SentEmail.objects.filter( |
| 137 | + recipient=waiting_list_proposal.speaker, |
| 138 | + email_template=proposal_in_waiting_list_template, |
| 139 | + conference=conference, |
| 140 | + placeholders={ |
| 141 | + "conference_name": conference.name.localize("en"), |
| 142 | + "proposal_title": waiting_list_proposal.title.localize("en"), |
| 143 | + "proposal_type": waiting_list_proposal.type.name, |
| 144 | + "speaker_name": "John", |
| 145 | + }, |
| 146 | + ).exists() |
0 commit comments