login
This commit is contained in:
@@ -3,12 +3,14 @@ import sys
|
||||
import os
|
||||
import flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import login_user
|
||||
|
||||
# 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
|
||||
from app.auth import auth
|
||||
import uuid
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@@ -35,13 +37,24 @@ def client(app):
|
||||
def mock_user(app):
|
||||
"""Create a mock user for testing."""
|
||||
user = User(
|
||||
email='test@example.com'
|
||||
first_name='Test',
|
||||
last_name='User',
|
||||
email='test@example.com',
|
||||
password_hash=b'hashed_password' # Will be properly hashed in real tests
|
||||
)
|
||||
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return user
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def authenticated_client(client, mock_user):
|
||||
"""Create a test client with authenticated user."""
|
||||
with client.session_transaction() as sess:
|
||||
sess['_user_id'] = str(mock_user.id)
|
||||
sess['_fresh'] = True
|
||||
return client
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_folder(app, mock_user):
|
||||
"""Create a mock folder for testing."""
|
||||
@@ -55,3 +68,17 @@ def mock_folder(app, mock_user):
|
||||
db.session.commit()
|
||||
return folder
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_user_with_password(app):
|
||||
"""Create a mock user with proper password hashing for testing."""
|
||||
user = User(
|
||||
first_name='Test',
|
||||
last_name='User',
|
||||
email='test@example.com'
|
||||
)
|
||||
user.set_password('testpassword')
|
||||
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user