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:
@@ -125,6 +125,32 @@ async def auth_client(app, test_user):
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def admin_client(app, db):
|
||||
"""Test client with an admin user pre-loaded in session."""
|
||||
now = datetime.now(UTC).isoformat()
|
||||
async with db.execute(
|
||||
"INSERT INTO users (email, name, created_at) VALUES (?, ?, ?)",
|
||||
("admin@test.com", "Admin", now),
|
||||
) as cursor:
|
||||
user_id = cursor.lastrowid
|
||||
await db.execute(
|
||||
"INSERT INTO user_roles (user_id, role) VALUES (?, 'admin')", (user_id,)
|
||||
)
|
||||
await db.commit()
|
||||
async with app.test_client() as c:
|
||||
async with c.session_transaction() as sess:
|
||||
sess["user_id"] = user_id
|
||||
yield c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_send_email():
|
||||
"""Patch padelnomics.worker.send_email for the duration of the test."""
|
||||
with patch("padelnomics.worker.send_email", new_callable=AsyncMock) as mock:
|
||||
yield mock
|
||||
|
||||
|
||||
# ── Subscriptions ────────────────────────────────────────────
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
Reference in New Issue
Block a user