generated from bisco/codex-bootstrap
fix: show local confirmation links before email send
This commit is contained in:
@@ -13,14 +13,12 @@ def build_confirmation_link(raw_confirmation_token):
|
|||||||
return f"{settings.SITE_BASE_URL}{CONFIRMATION_PATH}?token={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:
|
if not settings.LOG_RESERVATION_CONFIRMATION_URLS:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(
|
logger.warning(
|
||||||
"Local reservation confirmation link for manual testing (%s) for reservation %s: %s",
|
"LOCAL DEV confirmation URL: %s",
|
||||||
reason,
|
|
||||||
reservation.id,
|
|
||||||
confirmation_link,
|
confirmation_link,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,9 +34,7 @@ def send_confirmation_email(*, reservation, raw_confirmation_token):
|
|||||||
)
|
)
|
||||||
|
|
||||||
_log_confirmation_link_for_local_debug(
|
_log_confirmation_link_for_local_debug(
|
||||||
reservation=reservation,
|
|
||||||
confirmation_link=confirmation_link,
|
confirmation_link=confirmation_link,
|
||||||
reason="email send attempt",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -52,9 +48,8 @@ def send_confirmation_email(*, reservation, raw_confirmation_token):
|
|||||||
except Exception:
|
except Exception:
|
||||||
if settings.LOG_RESERVATION_CONFIRMATION_URLS:
|
if settings.LOG_RESERVATION_CONFIRMATION_URLS:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Failed to send confirmation email for reservation %s in local/debug mode.",
|
"Local/debug email delivery failed for reservation %s.",
|
||||||
reservation.id,
|
reservation.id,
|
||||||
exc_info=True,
|
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class BookingServiceTests(TestCase):
|
|||||||
SITE_BASE_URL="https://tickets.azionelab.example",
|
SITE_BASE_URL="https://tickets.azionelab.example",
|
||||||
)
|
)
|
||||||
def test_create_pending_reservation_logs_confirmation_link_in_local_mode(self):
|
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):
|
with self.captureOnCommitCallbacks(execute=True):
|
||||||
result = create_pending_reservation(
|
result = create_pending_reservation(
|
||||||
performance_id=self.performance.id,
|
performance_id=self.performance.id,
|
||||||
@@ -117,10 +117,7 @@ class BookingServiceTests(TestCase):
|
|||||||
self.assertEqual(result.reservation.status, Reservation.Status.PENDING)
|
self.assertEqual(result.reservation.status, Reservation.Status.PENDING)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
any(
|
any(
|
||||||
(
|
"LOCAL DEV confirmation URL:" in log_entry
|
||||||
"Local reservation confirmation link for manual testing "
|
|
||||||
"(email send attempt)"
|
|
||||||
) in log_entry
|
|
||||||
and result.raw_confirmation_token in log_entry
|
and result.raw_confirmation_token in log_entry
|
||||||
for log_entry in captured_logs.output
|
for log_entry in captured_logs.output
|
||||||
)
|
)
|
||||||
@@ -160,7 +157,7 @@ class BookingServiceTests(TestCase):
|
|||||||
self,
|
self,
|
||||||
mocked_send_mail,
|
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):
|
with self.captureOnCommitCallbacks(execute=True):
|
||||||
result = create_pending_reservation(
|
result = create_pending_reservation(
|
||||||
performance_id=self.performance.id,
|
performance_id=self.performance.id,
|
||||||
@@ -174,16 +171,13 @@ class BookingServiceTests(TestCase):
|
|||||||
confirmation_log_index = next(
|
confirmation_log_index = next(
|
||||||
index
|
index
|
||||||
for index, log_entry in enumerate(captured_logs.output)
|
for index, log_entry in enumerate(captured_logs.output)
|
||||||
if (
|
if "LOCAL DEV confirmation URL:" in log_entry
|
||||||
"Local reservation confirmation link for manual testing "
|
|
||||||
"(email send attempt)"
|
|
||||||
) in log_entry
|
|
||||||
and result.raw_confirmation_token in log_entry
|
and result.raw_confirmation_token in log_entry
|
||||||
)
|
)
|
||||||
failure_log_index = next(
|
failure_log_index = next(
|
||||||
index
|
index
|
||||||
for index, log_entry in enumerate(captured_logs.output)
|
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)
|
self.assertLess(confirmation_log_index, failure_log_index)
|
||||||
@@ -194,6 +188,9 @@ class BookingServiceTests(TestCase):
|
|||||||
),
|
),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
|
self.assertFalse(
|
||||||
|
any("Traceback" in log_entry for log_entry in captured_logs.output)
|
||||||
|
)
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
LOG_RESERVATION_CONFIRMATION_URLS=False,
|
LOG_RESERVATION_CONFIRMATION_URLS=False,
|
||||||
@@ -204,7 +201,7 @@ class BookingServiceTests(TestCase):
|
|||||||
self,
|
self,
|
||||||
mocked_send_mail,
|
mocked_send_mail,
|
||||||
):
|
):
|
||||||
with self.assertNoLogs("bookings.emailing", level="INFO"):
|
with self.assertNoLogs("bookings.emailing", level="WARNING"):
|
||||||
with self.captureOnCommitCallbacks(execute=True):
|
with self.captureOnCommitCallbacks(execute=True):
|
||||||
result = create_pending_reservation(
|
result = create_pending_reservation(
|
||||||
performance_id=self.performance.id,
|
performance_id=self.performance.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user