From 0275dcbd0a6a3fac28946d031df930bcbefd03ca Mon Sep 17 00:00:00 2001 From: aviupadhyayula Date: Wed, 9 Oct 2024 10:29:22 -0400 Subject: [PATCH] Fix ticket confirmations & add test --- backend/clubs/views.py | 12 +++++++----- backend/tests/clubs/test_ticketing.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/clubs/views.py b/backend/clubs/views.py index 199e59d04..02ebffd1a 100644 --- a/backend/clubs/views.py +++ b/backend/clubs/views.py @@ -5620,17 +5620,19 @@ def _give_tickets(user, order_info, cart, reconciliation_id): buyer_phone=order_info["billTo"].get("phoneNumber", None), buyer_email=order_info["billTo"]["email"], ) - tickets.update(owner=user, holder=None, transaction_record=transaction_record) - cart.tickets.clear() - for ticket in tickets: - ticket.send_confirmation_email() + cart.tickets.clear() Ticket.objects.update_holds() - cart.checkout_context = None cart.save() + tickets = Ticket.objects.filter( + owner=user, transaction_record=transaction_record + ) + for ticket in tickets: + ticket.send_confirmation_email() + @staticmethod def _place_hold_on_tickets(user, tickets): """ diff --git a/backend/tests/clubs/test_ticketing.py b/backend/tests/clubs/test_ticketing.py index 359bee9f3..e1572ae4d 100644 --- a/backend/tests/clubs/test_ticketing.py +++ b/backend/tests/clubs/test_ticketing.py @@ -6,6 +6,7 @@ import freezegun from django.contrib.auth import get_user_model +from django.core import mail from django.db.models import Count from django.db.models.deletion import ProtectedError from django.test import TestCase @@ -1019,6 +1020,18 @@ def test_give_tickets(self): ).exists() self.assertTrue(record_exists) + # Check that confirmation emails were sent + self.assertEqual(len(mail.outbox), len(tickets_to_add)) + for msg in mail.outbox: + self.assertIn( + f"Ticket confirmation for {self.user1.first_name} " + f"{self.user1.last_name}", + msg.subject, + ) + self.assertIn(self.user1.first_name, msg.body) + self.assertIn(self.event1.name, msg.body) + self.assertIsNotNone(msg.attachments) + def test_initiate_checkout_non_free_tickets(self): self.client.login(username=self.user1.username, password="test")