Files
sneakyklaus/tests/conftest.py
Phil Skentelbery 6a2ac7a8a7 feat: implement initial admin setup (Story 1.1)
Add complete initial admin setup functionality including:
- SetupForm with email, password, and password confirmation fields
- Password validation (minimum 12 characters) and confirmation matching
- Email format validation
- Setup route with GET (display form) and POST (process setup) handlers
- bcrypt password hashing before storing admin credentials
- Auto-login after successful setup with session management
- First-run detection middleware that redirects to /setup if no admin exists
- Setup page returns 404 after admin account is created
- Base HTML template with Pico CSS integration
- Admin dashboard placeholder template
- 404 error template

All tests pass with 90.09% code coverage (exceeds 80% requirement).
Code passes ruff linting and mypy type checking.

Story: 1.1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-22 11:40:38 -07:00

78 lines
1.7 KiB
Python

"""Pytest configuration and shared fixtures for Sneaky Klaus tests."""
import pytest
from src.app import create_app
from src.app import db as _db
from src.models import Admin
@pytest.fixture(scope="session")
def app():
"""Create and configure a test Flask application instance.
This fixture is scoped to the session so the app is created once
for all tests.
Yields:
Flask application configured for testing.
"""
app = create_app("testing")
yield app
@pytest.fixture(scope="function")
def db(app):
"""Create a clean database for each test.
This fixture creates all tables before each test and drops them
after each test to ensure isolation.
Args:
app: Flask application instance from app fixture.
Yields:
SQLAlchemy database instance.
"""
with app.app_context():
_db.create_all()
yield _db
_db.session.remove()
_db.drop_all()
@pytest.fixture(scope="function")
def client(app, db): # noqa: ARG001
"""Create a test client for the Flask application.
Args:
app: Flask application instance.
db: Database instance (ensures db is set up first).
Yields:
Flask test client.
"""
with app.test_client() as client:
yield client
@pytest.fixture
def admin(db):
"""Create an admin user for testing.
Args:
db: Database instance.
Returns:
Admin model instance.
"""
from src.app import bcrypt
admin = Admin(
email="admin@example.com",
password_hash=bcrypt.generate_password_hash("testpassword123").decode("utf-8"),
)
db.session.add(admin)
db.session.commit()
return admin