This commit is contained in:
Bryce
2025-08-03 21:35:22 -07:00
parent 21d3a710f2
commit 9df259eb58
26 changed files with 476 additions and 363 deletions

View File

@@ -1,6 +1,8 @@
import pytest
import sys
import os
import flask
from flask_sqlalchemy import SQLAlchemy
# Add the project root directory to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
@@ -9,45 +11,47 @@ from app import create_app, db
from app.models import User, Folder
import uuid
@pytest.fixture
@pytest.fixture(scope="function")
def app():
"""Create application for testing."""
"""Create a fresh app with in-memory database for each test."""
app = create_app('testing')
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' # In-memory database for tests
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # Recommended for Flask-SQLAlchemy
with app.app_context():
db.create_all()
yield app
db.drop_all()
db.create_all() # Create tables for your models
db.session.begin()
yield app # Yield the app for tests to use
db.session.close()
db.drop_all() # Clean up after tests
@pytest.fixture
def client(app):
"""A test client for the app."""
return app.test_client()
@pytest.fixture
@pytest.fixture(scope="function")
def mock_user(app):
"""Create a mock user for testing."""
with app.app_context():
user = User(
id=uuid.UUID('123e4567-e89b-12d3-a456-426614174000'),
email='test@example.com'
)
db.session.add(user)
db.session.commit()
return user
user = User(
email='test@example.com'
)
db.session.add(user)
db.session.commit()
return user
@pytest.fixture
@pytest.fixture(scope="function")
def mock_folder(app, mock_user):
"""Create a mock folder for testing."""
with app.app_context():
folder = Folder(
user_id=mock_user.id,
name='Test Folder',
rule_text='Test rule',
priority=1
)
db.session.add(folder)
db.session.commit()
return folder
folder = Folder(
user_id=mock_user.id,
name='Test Folder',
rule_text='Test rule',
priority=1
)
db.session.add(folder)
db.session.commit()
return folder