|
2 | 2 | from unittest import mock |
3 | 3 |
|
4 | 4 | import pytz |
| 5 | +from django.core import mail |
5 | 6 | from django.urls import reverse |
6 | 7 |
|
7 | 8 | from contentcuration.constants import ( |
|
16 | 17 | from contentcuration.tests import testdata |
17 | 18 | from contentcuration.tests.base import StudioAPITestCase |
18 | 19 | from contentcuration.tests.helpers import reverse_with_query |
| 20 | +from contentcuration.utils.urls import canonical_url |
19 | 21 | from contentcuration.viewsets.sync.constants import ADDED_TO_COMMUNITY_LIBRARY |
20 | 22 |
|
21 | 23 |
|
@@ -731,6 +733,58 @@ def test_resolve_submission__accept_correct(self, apply_task_mock): |
731 | 733 | channel_id=self.submission.channel.id, |
732 | 734 | ) |
733 | 735 |
|
| 736 | + self.assertEqual(len(mail.outbox), 1) |
| 737 | + sent_email = mail.outbox[0] |
| 738 | + self.assertEqual(sent_email.to, [self.submission.author.email]) |
| 739 | + self.assertIn("approved", sent_email.subject.lower()) |
| 740 | + self.assertIn("approved", sent_email.body.lower()) |
| 741 | + self.assertIn(self.submission.channel.name, sent_email.body) |
| 742 | + self.assertIn( |
| 743 | + canonical_url( |
| 744 | + reverse("channel", kwargs={"channel_id": self.submission.channel.pk}) |
| 745 | + ), |
| 746 | + sent_email.body, |
| 747 | + ) |
| 748 | + |
| 749 | + @mock.patch( |
| 750 | + "contentcuration.viewsets.community_library_submission.apply_channel_changes_task" |
| 751 | + ) |
| 752 | + @mock.patch( |
| 753 | + "contentcuration.models.CommunityLibrarySubmission.send_resolution_email", |
| 754 | + side_effect=Exception("SMTP is down"), |
| 755 | + ) |
| 756 | + def test_resolve_submission__accept_correct_when_email_fails( |
| 757 | + self, send_email_mock, apply_task_mock |
| 758 | + ): |
| 759 | + """A failure to notify the author shouldn't undo or fail the resolution.""" |
| 760 | + self.client.force_authenticate(user=self.admin_user) |
| 761 | + response = self.client.post( |
| 762 | + reverse( |
| 763 | + "admin-community-library-submission-resolve", |
| 764 | + args=[self.submission.id], |
| 765 | + ), |
| 766 | + self.resolve_approve_metadata, |
| 767 | + format="json", |
| 768 | + ) |
| 769 | + self.assertEqual(response.status_code, 200, response.content) |
| 770 | + |
| 771 | + resolved_submission = CommunityLibrarySubmission.objects.get( |
| 772 | + id=self.submission.id |
| 773 | + ) |
| 774 | + self.assertEqual( |
| 775 | + resolved_submission.status, |
| 776 | + community_library_submission_constants.STATUS_APPROVED, |
| 777 | + ) |
| 778 | + Change.objects.get( |
| 779 | + channel=self.submission.channel, |
| 780 | + change_type=ADDED_TO_COMMUNITY_LIBRARY, |
| 781 | + ) |
| 782 | + apply_task_mock.fetch_or_enqueue.assert_called_once_with( |
| 783 | + self.admin_user, |
| 784 | + channel_id=self.submission.channel.id, |
| 785 | + ) |
| 786 | + self.assertEqual(len(mail.outbox), 0) |
| 787 | + |
734 | 788 | @mock.patch( |
735 | 789 | "contentcuration.viewsets.community_library_submission.apply_channel_changes_task" |
736 | 790 | ) |
@@ -770,6 +824,20 @@ def test_resolve_submission__reject_correct(self, apply_task_mock): |
770 | 824 | ) |
771 | 825 | apply_task_mock.fetch_or_enqueue.assert_not_called() |
772 | 826 |
|
| 827 | + self.assertEqual(len(mail.outbox), 1) |
| 828 | + sent_email = mail.outbox[0] |
| 829 | + self.assertEqual(sent_email.to, [self.submission.author.email]) |
| 830 | + self.assertIn("needs changes", sent_email.subject.lower()) |
| 831 | + self.assertIn("needs changes", sent_email.body.lower()) |
| 832 | + self.assertIn(self.submission.channel.name, sent_email.body) |
| 833 | + self.assertIn( |
| 834 | + canonical_url( |
| 835 | + reverse("channel", kwargs={"channel_id": self.submission.channel.pk}) |
| 836 | + ), |
| 837 | + sent_email.body, |
| 838 | + ) |
| 839 | + self.assertIn(self.feedback_notes, sent_email.body) |
| 840 | + |
773 | 841 | def test_resolve_submission__reject_missing_resolution_reason(self): |
774 | 842 | self.client.force_authenticate(user=self.admin_user) |
775 | 843 | metadata = self.resolve_reject_metadata.copy() |
|
0 commit comments