refactor(tests): compress admin_client + mock_send_email into conftest
Lift admin_client fixture from 7 duplicate definitions into conftest.py. Add mock_send_email fixture, replacing 60 inline patch() blocks across test_emails.py, test_waitlist.py, and test_businessplan.py. Net -197 lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -188,59 +188,55 @@ class TestWorkerTask:
|
||||
"""Test send_waitlist_confirmation worker task."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sends_entrepreneur_confirmation(self):
|
||||
async def test_sends_entrepreneur_confirmation(self, mock_send_email):
|
||||
"""Task sends confirmation email for entrepreneur signup."""
|
||||
with patch("padelnomics.worker.send_email", new_callable=AsyncMock) as mock_send:
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "entrepreneur@example.com",
|
||||
"intent": "signup",
|
||||
})
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "entrepreneur@example.com",
|
||||
"intent": "signup",
|
||||
})
|
||||
|
||||
mock_send.assert_called_once()
|
||||
call_args = mock_send.call_args
|
||||
assert call_args.kwargs["to"] == "entrepreneur@example.com"
|
||||
assert "notify you at launch" in call_args.kwargs["subject"].lower()
|
||||
assert "waitlist" in call_args.kwargs["html"].lower()
|
||||
mock_send_email.assert_called_once()
|
||||
call_args = mock_send_email.call_args
|
||||
assert call_args.kwargs["to"] == "entrepreneur@example.com"
|
||||
assert "notify you at launch" in call_args.kwargs["subject"].lower()
|
||||
assert "waitlist" in call_args.kwargs["html"].lower()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_sends_supplier_confirmation(self):
|
||||
async def test_sends_supplier_confirmation(self, mock_send_email):
|
||||
"""Task sends confirmation email for supplier signup."""
|
||||
with patch("padelnomics.worker.send_email", new_callable=AsyncMock) as mock_send:
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "supplier@example.com",
|
||||
"intent": "supplier_growth",
|
||||
})
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "supplier@example.com",
|
||||
"intent": "supplier_growth",
|
||||
})
|
||||
|
||||
mock_send.assert_called_once()
|
||||
call_args = mock_send.call_args
|
||||
assert call_args.kwargs["to"] == "supplier@example.com"
|
||||
assert "growth" in call_args.kwargs["subject"].lower()
|
||||
assert "supplier" in call_args.kwargs["html"].lower()
|
||||
mock_send_email.assert_called_once()
|
||||
call_args = mock_send_email.call_args
|
||||
assert call_args.kwargs["to"] == "supplier@example.com"
|
||||
assert "growth" in call_args.kwargs["subject"].lower()
|
||||
assert "supplier" in call_args.kwargs["html"].lower()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_supplier_email_includes_plan_name(self):
|
||||
async def test_supplier_email_includes_plan_name(self, mock_send_email):
|
||||
"""Supplier confirmation should mention the specific plan."""
|
||||
with patch("padelnomics.worker.send_email", new_callable=AsyncMock) as mock_send:
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "supplier@example.com",
|
||||
"intent": "supplier_pro",
|
||||
})
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "supplier@example.com",
|
||||
"intent": "supplier_pro",
|
||||
})
|
||||
|
||||
call_args = mock_send.call_args
|
||||
html = call_args.kwargs["html"]
|
||||
assert "pro" in html.lower()
|
||||
call_args = mock_send_email.call_args
|
||||
html = call_args.kwargs["html"]
|
||||
assert "pro" in html.lower()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_uses_transactional_email_address(self):
|
||||
async def test_uses_transactional_email_address(self, mock_send_email):
|
||||
"""Task should use transactional sender address."""
|
||||
with patch("padelnomics.worker.send_email", new_callable=AsyncMock) as mock_send:
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "test@example.com",
|
||||
"intent": "signup",
|
||||
})
|
||||
await handle_send_waitlist_confirmation({
|
||||
"email": "test@example.com",
|
||||
"intent": "signup",
|
||||
})
|
||||
|
||||
call_args = mock_send.call_args
|
||||
assert call_args.kwargs["from_addr"] == core.EMAIL_ADDRESSES["transactional"]
|
||||
call_args = mock_send_email.call_args
|
||||
assert call_args.kwargs["from_addr"] == core.EMAIL_ADDRESSES["transactional"]
|
||||
|
||||
|
||||
# ── TestAuthRoutes ────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user