53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import pytest
|
|
import sys
|
|
import os
|
|
|
|
# Add the project root directory to the Python path
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
|
|
|
|
from app import create_app, db
|
|
from app.models import User, Folder
|
|
import uuid
|
|
|
|
@pytest.fixture
|
|
def app():
|
|
"""Create application for testing."""
|
|
app = create_app('testing')
|
|
app.config['TESTING'] = True
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' # In-memory database for tests
|
|
|
|
with app.app_context():
|
|
db.create_all()
|
|
yield app
|
|
db.drop_all()
|
|
|
|
@pytest.fixture
|
|
def client(app):
|
|
"""A test client for the app."""
|
|
return app.test_client()
|
|
|
|
@pytest.fixture
|
|
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
|
|
|
|
@pytest.fixture
|
|
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 |