40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
import pytest
|
|
from werkzeug.security import generate_password_hash
|
|
from app import create_app
|
|
from config import TestConfig
|
|
from app.extensions import db
|
|
from app.models.user import User
|
|
from app.models.company import Company, UserCompanyAccess
|
|
from app.models.setting import AppSetting
|
|
|
|
|
|
@pytest.fixture()
|
|
def app():
|
|
app = create_app(TestConfig)
|
|
with app.app_context():
|
|
db.create_all()
|
|
company = Company(name='Test Co', tax_id='123', sync_enabled=True, sync_interval_minutes=60)
|
|
db.session.add(company)
|
|
db.session.flush()
|
|
user = User(email='admin@example.com', name='Admin', password_hash=generate_password_hash('Admin123!'), role='admin')
|
|
db.session.add(user)
|
|
db.session.flush()
|
|
db.session.add(UserCompanyAccess(user_id=user.id, company_id=company.id, access_level='full'))
|
|
AppSetting.set(f'company.{company.id}.notify.enabled', 'true')
|
|
AppSetting.set(f'company.{company.id}.notify.min_amount', '0')
|
|
AppSetting.set(f'company.{company.id}.ksef.mock_mode', 'true')
|
|
db.session.commit()
|
|
yield app
|
|
db.drop_all()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(app):
|
|
return app.test_client()
|
|
|
|
|
|
@pytest.fixture()
|
|
def auth_client(client):
|
|
client.post('/auth/login', data={'email': 'admin@example.com', 'password': 'Admin123!'}, follow_redirects=True)
|
|
return client
|