Fix feedback email test for on_commit task enqueue
Execute on_commit callbacks so OutboundEmail ImmediateBackend send runs inside TestCase transactions, matching invite/reset coverage.
This commit is contained in:
@@ -375,17 +375,21 @@ class FeedbackViewTestCase(APITestCase):
|
||||
self.url = reverse("feedbacks")
|
||||
|
||||
def test_post_creates_feedback_and_notifies(self):
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"title": "Broken button", "text": "It does nothing"},
|
||||
format="json",
|
||||
)
|
||||
with self.captureOnCommitCallbacks(execute=True):
|
||||
response = self.client.post(
|
||||
self.url,
|
||||
{"title": "Broken button", "text": "It does nothing"},
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
feedback = Feedback.objects.get()
|
||||
self.assertEqual(feedback.user, self.user)
|
||||
self.assertEqual(len(mail.outbox), 1)
|
||||
self.assertIn("Broken button", mail.outbox[0].body)
|
||||
outbound = OutboundEmail.objects.get(user=self.user)
|
||||
self.assertEqual(outbound.kind, OutboundEmail.Kind.FEEDBACK)
|
||||
self.assertEqual(outbound.status, OutboundEmail.Status.SENT)
|
||||
|
||||
def test_post_without_text_is_rejected(self):
|
||||
response = self.client.post(self.url, {"title": "no body"}, format="json")
|
||||
|
||||
Reference in New Issue
Block a user