Files
Reklamator/tests/conftest.py
T

90 lines
2.1 KiB
Python
Raw Normal View History

"""Pytest configuration and fixtures"""
import os
import pytest
import tempfile
import shutil
from app import create_app
from app.models.user import User
@pytest.fixture
def app():
"""Create application for testing"""
app = create_app('testing')
# Create temporary data directory
with app.app_context():
os.makedirs(app.config['DATA_DIR'], exist_ok=True)
yield app
# Cleanup temporary directory
with app.app_context():
if os.path.exists(app.config['DATA_DIR']):
shutil.rmtree(app.config['DATA_DIR'])
@pytest.fixture
def client(app):
"""Create test client"""
return app.test_client()
@pytest.fixture
def runner(app):
"""Create test CLI runner"""
return app.test_cli_runner()
@pytest.fixture
def admin_user(app):
"""Create administrator user for testing"""
with app.app_context():
user = User.create(
username='admin',
email='admin@example.com',
password='admin123',
role='administrator'
)
yield user
# Cleanup
user.delete()
@pytest.fixture
def product_owner_user(app):
"""Create product owner user for testing"""
with app.app_context():
user = User.create(
username='owner',
email='owner@example.com',
password='owner123',
role='product_owner',
product_ids=['prod_0001']
)
yield user
# Cleanup
user.delete()
@pytest.fixture
def authenticated_admin_client(client, admin_user):
"""Create authenticated admin client"""
with client:
client.post('/auth/login', data={
'username': 'admin',
'password': 'admin123'
}, follow_redirects=True)
yield client
@pytest.fixture
def authenticated_owner_client(client, product_owner_user):
"""Create authenticated product owner client"""
with client:
client.post('/auth/login', data={
'username': 'owner',
'password': 'owner123'
}, follow_redirects=True)
yield client