"""Test configuration and fixtures""" import pytest from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from fastapi.testclient import TestClient from app.main import app from app.core.database import Base, get_db from app.core.config import settings # Test database setup TEST_DATABASE_URL = "sqlite:///test.db" engine = create_engine( TEST_DATABASE_URL, connect_args={"check_same_thread": False}, ) TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) def override_get_db(): """Override get_db for testing""" try: db = TestingSessionLocal() yield db finally: db.close() @pytest.fixture(scope="function") def test_db(): """Create test database and tables""" Base.metadata.create_all(bind=engine) yield Base.metadata.drop_all(bind=engine) @pytest.fixture(scope="function") def client(test_db): """Create test client with overridden database""" app.dependency_overrides[get_db] = override_get_db with TestClient(app) as test_client: yield test_client app.dependency_overrides.clear() @pytest.fixture def test_user_data(): """Test user registration data""" return { "email": "test@example.com", "password": "TestPassword123", "full_name": "Test User" } @pytest.fixture def test_login_data(): """Test login credentials""" return { "email": "test@example.com", "password": "TestPassword123" }