lots of progress on input processing
This commit is contained in:
53
tests/conftest.py
Normal file
53
tests/conftest.py
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
33
tests/test_models.py
Normal file
33
tests/test_models.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pytest
|
||||
from app.models import User, Folder
|
||||
import uuid
|
||||
|
||||
def test_user_model(app, mock_user):
|
||||
"""Test User model creation and properties."""
|
||||
with app.app_context():
|
||||
# Test user was created by fixture
|
||||
assert mock_user.id == uuid.UUID('123e4567-e89b-12d3-a456-426614174000')
|
||||
assert mock_user.email == 'test@example.com'
|
||||
|
||||
# Test querying user
|
||||
user_from_db = User.query.filter_by(email='test@example.com').first()
|
||||
assert user_from_db is not None
|
||||
assert user_from_db.id == mock_user.id
|
||||
|
||||
def test_folder_model(app, mock_folder, mock_user):
|
||||
"""Test Folder model creation and properties."""
|
||||
with app.app_context():
|
||||
# Test folder was created by fixture
|
||||
assert mock_folder.user_id == mock_user.id
|
||||
assert mock_folder.name == 'Test Folder'
|
||||
assert mock_folder.rule_text == 'Test rule'
|
||||
assert mock_folder.priority == 1
|
||||
|
||||
# Test relationship
|
||||
assert len(mock_user.folders) == 1
|
||||
assert mock_user.folders[0].id == mock_folder.id
|
||||
|
||||
# Test querying folder
|
||||
folder_from_db = Folder.query.filter_by(name='Test Folder').first()
|
||||
assert folder_from_db is not None
|
||||
assert folder_from_db.user_id == mock_user.id
|
||||
31
tests/test_routes.py
Normal file
31
tests/test_routes.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import pytest
|
||||
from app.models import User
|
||||
import uuid
|
||||
|
||||
def test_index_route(client, app):
|
||||
"""Test that the index route loads successfully."""
|
||||
with app.app_context():
|
||||
# Create a mock user for the test
|
||||
mock_user = User(
|
||||
id=uuid.UUID('123e4567-e89b-12d3-a456-426614174000'),
|
||||
email='test@example.com'
|
||||
)
|
||||
from app import db
|
||||
db.session.add(mock_user)
|
||||
db.session.commit()
|
||||
|
||||
response = client.get('/')
|
||||
assert response.status_code == 200
|
||||
# Check if the page contains expected elements
|
||||
assert b'Email Organizer' in response.data
|
||||
assert b'Folders' in response.data
|
||||
|
||||
def test_add_folder_route(client):
|
||||
"""Test the add folder API endpoint."""
|
||||
response = client.post('/api/folders',
|
||||
json={'name': 'Test Folder', 'rule_text': 'Test rule'},
|
||||
content_type='application/json')
|
||||
|
||||
assert response.status_code == 201
|
||||
assert b'Folder added (mock)' in response.data
|
||||
assert b'Test Folder' in response.data
|
||||
Reference in New Issue
Block a user