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:
@@ -9,7 +9,6 @@ Admin gallery tests: access control, list page, preview page, error handling.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from padelnomics.core import utcnow_iso
|
||||
from padelnomics.email_templates import EMAIL_TEMPLATE_REGISTRY, render_email_template
|
||||
|
||||
# ── render_email_template() ──────────────────────────────────────────────────
|
||||
@@ -124,26 +123,6 @@ class TestRenderEmailTemplate:
|
||||
# ── Admin gallery routes ──────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def admin_client(app, db):
|
||||
"""Test client with a user that has the admin role."""
|
||||
now = utcnow_iso()
|
||||
async with db.execute(
|
||||
"INSERT INTO users (email, name, created_at) VALUES (?, ?, ?)",
|
||||
("gallery_admin@test.com", "Gallery Admin", now),
|
||||
) as cursor:
|
||||
admin_id = cursor.lastrowid
|
||||
await db.execute(
|
||||
"INSERT INTO user_roles (user_id, role) VALUES (?, 'admin')", (admin_id,)
|
||||
)
|
||||
await db.commit()
|
||||
|
||||
async with app.test_client() as c:
|
||||
async with c.session_transaction() as sess:
|
||||
sess["user_id"] = admin_id
|
||||
yield c
|
||||
|
||||
|
||||
class TestEmailGalleryRoutes:
|
||||
@pytest.mark.asyncio
|
||||
async def test_gallery_requires_auth(self, client):
|
||||
|
||||
Reference in New Issue
Block a user