Introduce comprehensive tests for the Event model, covering creation, updates, deletions, relationships, defaults, and constraints. Added the `mock_user` fixture to streamline user-related test setups and ensure proper linkage between users and events. Improves test coverage and ensures model behavior consistency.
42 lines
1.0 KiB
Python
42 lines
1.0 KiB
Python
# tests/conftest.py
|
|
import pytest
|
|
import uuid
|
|
from app.models.user import User
|
|
from app.utils.test_utils import setup_test_db, teardown_test_db
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def db_session():
|
|
"""
|
|
Creates a fresh SQLite in-memory database for each test function.
|
|
|
|
Yields a SQLAlchemy session that can be used for testing.
|
|
"""
|
|
# Set up the database
|
|
test_engine, TestingSessionLocal = setup_test_db()
|
|
|
|
# Create a session
|
|
with TestingSessionLocal() as session:
|
|
yield session
|
|
|
|
# Clean up
|
|
teardown_test_db(test_engine)
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_user(db_session):
|
|
"""Fixture to create and return a mock User instance."""
|
|
mock_user = User(
|
|
id=uuid.uuid4(),
|
|
email="mockuser@example.com",
|
|
password_hash="mockhashedpassword",
|
|
first_name="Mock",
|
|
last_name="User",
|
|
phone_number="1234567890",
|
|
is_active=True,
|
|
is_superuser=False
|
|
)
|
|
db_session.add(mock_user)
|
|
db_session.commit()
|
|
return mock_user
|