diff --git a/backend/bookings/emailing.py b/backend/bookings/emailing.py index 112ffb8..00c30d6 100644 --- a/backend/bookings/emailing.py +++ b/backend/bookings/emailing.py @@ -13,14 +13,12 @@ def build_confirmation_link(raw_confirmation_token): return f"{settings.SITE_BASE_URL}{CONFIRMATION_PATH}?token={raw_confirmation_token}" -def _log_confirmation_link_for_local_debug(*, reservation, confirmation_link, reason): +def _log_confirmation_link_for_local_debug(*, confirmation_link): if not settings.LOG_RESERVATION_CONFIRMATION_URLS: return - logger.info( - "Local reservation confirmation link for manual testing (%s) for reservation %s: %s", - reason, - reservation.id, + logger.warning( + "LOCAL DEV confirmation URL: %s", confirmation_link, ) @@ -36,9 +34,7 @@ def send_confirmation_email(*, reservation, raw_confirmation_token): ) _log_confirmation_link_for_local_debug( - reservation=reservation, confirmation_link=confirmation_link, - reason="email send attempt", ) try: @@ -52,9 +48,8 @@ def send_confirmation_email(*, reservation, raw_confirmation_token): except Exception: if settings.LOG_RESERVATION_CONFIRMATION_URLS: logger.warning( - "Failed to send confirmation email for reservation %s in local/debug mode.", + "Local/debug email delivery failed for reservation %s.", reservation.id, - exc_info=True, ) return diff --git a/backend/bookings/test_services.py b/backend/bookings/test_services.py index aa0f0a4..af5e972 100644 --- a/backend/bookings/test_services.py +++ b/backend/bookings/test_services.py @@ -105,7 +105,7 @@ class BookingServiceTests(TestCase): SITE_BASE_URL="https://tickets.azionelab.example", ) def test_create_pending_reservation_logs_confirmation_link_in_local_mode(self): - with self.assertLogs("bookings.emailing", level="INFO") as captured_logs: + with self.assertLogs("bookings.emailing", level="WARNING") as captured_logs: with self.captureOnCommitCallbacks(execute=True): result = create_pending_reservation( performance_id=self.performance.id, @@ -117,10 +117,7 @@ class BookingServiceTests(TestCase): self.assertEqual(result.reservation.status, Reservation.Status.PENDING) self.assertTrue( any( - ( - "Local reservation confirmation link for manual testing " - "(email send attempt)" - ) in log_entry + "LOCAL DEV confirmation URL:" in log_entry and result.raw_confirmation_token in log_entry for log_entry in captured_logs.output ) @@ -160,7 +157,7 @@ class BookingServiceTests(TestCase): self, mocked_send_mail, ): - with self.assertLogs("bookings.emailing", level="INFO") as captured_logs: + with self.assertLogs("bookings.emailing", level="WARNING") as captured_logs: with self.captureOnCommitCallbacks(execute=True): result = create_pending_reservation( performance_id=self.performance.id, @@ -174,16 +171,13 @@ class BookingServiceTests(TestCase): confirmation_log_index = next( index for index, log_entry in enumerate(captured_logs.output) - if ( - "Local reservation confirmation link for manual testing " - "(email send attempt)" - ) in log_entry + if "LOCAL DEV confirmation URL:" in log_entry and result.raw_confirmation_token in log_entry ) failure_log_index = next( index for index, log_entry in enumerate(captured_logs.output) - if "Failed to send confirmation email for reservation" in log_entry + if "Local/debug email delivery failed for reservation" in log_entry ) self.assertLess(confirmation_log_index, failure_log_index) @@ -194,6 +188,9 @@ class BookingServiceTests(TestCase): ), 1, ) + self.assertFalse( + any("Traceback" in log_entry for log_entry in captured_logs.output) + ) @override_settings( LOG_RESERVATION_CONFIRMATION_URLS=False, @@ -204,7 +201,7 @@ class BookingServiceTests(TestCase): self, mocked_send_mail, ): - with self.assertNoLogs("bookings.emailing", level="INFO"): + with self.assertNoLogs("bookings.emailing", level="WARNING"): with self.captureOnCommitCallbacks(execute=True): result = create_pending_reservation( performance_id=self.performance.id,