fix: use print instead of logger for dev mode email output
Logger.info wasn't visible in gunicorn container logs. Using print with flush=True ensures magic link URLs are visible in container logs for QA testing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"""Tests for email service."""
|
||||
|
||||
import logging
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -89,26 +88,26 @@ class TestEmailService:
|
||||
assert call_args["from"] == "custom@example.com"
|
||||
|
||||
@patch("resend.Emails.send")
|
||||
def test_send_email_in_dev_mode_logs_instead(self, mock_send, app, caplog):
|
||||
"""Test that email sending logs in dev mode instead of actually sending."""
|
||||
def test_send_email_in_dev_mode_logs_instead(self, mock_send, app, capsys):
|
||||
"""Test that email sending prints in dev mode instead of actually sending."""
|
||||
with app.app_context():
|
||||
app.config["FLASK_ENV"] = "development"
|
||||
service = EmailService()
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
result = service.send_email(
|
||||
to="test@example.com",
|
||||
subject="Test Subject",
|
||||
html_body="<p>Test body</p>",
|
||||
)
|
||||
result = service.send_email(
|
||||
to="test@example.com",
|
||||
subject="Test Subject",
|
||||
html_body="<p>Test body</p>",
|
||||
)
|
||||
|
||||
# Should not actually send email
|
||||
mock_send.assert_not_called()
|
||||
|
||||
# Should log the email details
|
||||
assert "DEV MODE: Email not sent" in caplog.text
|
||||
assert "test@example.com" in caplog.text
|
||||
assert "Test Subject" in caplog.text
|
||||
# Should print the email details
|
||||
captured = capsys.readouterr()
|
||||
assert "DEV MODE: Email not sent" in captured.out
|
||||
assert "test@example.com" in captured.out
|
||||
assert "Test Subject" in captured.out
|
||||
|
||||
# Should return a mock success response
|
||||
assert result["id"].startswith("dev-mode-")
|
||||
@@ -182,20 +181,20 @@ class TestEmailService:
|
||||
assert "$25-50" in call_args["html_body"]
|
||||
assert "2025-12-20" in call_args["html_body"]
|
||||
|
||||
def test_dev_mode_logs_magic_link_url(self, app, caplog):
|
||||
"""Test that magic link URLs are logged in dev mode."""
|
||||
def test_dev_mode_logs_magic_link_url(self, app, capsys):
|
||||
"""Test that magic link URLs are printed in dev mode."""
|
||||
with app.app_context():
|
||||
app.config["FLASK_ENV"] = "development"
|
||||
service = EmailService()
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
service.send_magic_link(
|
||||
to="test@example.com",
|
||||
magic_link_url="https://example.com/magic/abc123",
|
||||
exchange_name="Secret Santa 2025",
|
||||
)
|
||||
service.send_magic_link(
|
||||
to="test@example.com",
|
||||
magic_link_url="https://example.com/magic/abc123",
|
||||
exchange_name="Secret Santa 2025",
|
||||
)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert (
|
||||
"DEV MODE: Magic link URL: https://example.com/magic/abc123"
|
||||
in caplog.text
|
||||
in captured.out
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user