first commit
This commit is contained in:
49
tests/conftest.py
Normal file
49
tests/conftest.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import pytest
|
||||
|
||||
from app import create_app
|
||||
from app.config import TestConfig
|
||||
from app.extensions import db
|
||||
from app.models import User, seed_categories, seed_default_settings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
app = create_app(TestConfig)
|
||||
with app.app_context():
|
||||
db.drop_all()
|
||||
db.create_all()
|
||||
seed_categories()
|
||||
seed_default_settings()
|
||||
admin = User(email='admin@test.com', full_name='Admin', role='admin', must_change_password=False, language='pl')
|
||||
admin.set_password('Password123!')
|
||||
user = User(email='user@test.com', full_name='User', role='user', must_change_password=False, language='pl')
|
||||
user.set_password('Password123!')
|
||||
db.session.add_all([admin, user])
|
||||
db.session.commit()
|
||||
yield app
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(app):
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def runner(app):
|
||||
return app.test_cli_runner()
|
||||
|
||||
|
||||
def login(client, email='user@test.com', password='Password123!'):
|
||||
return client.post('/login', data={'email': email, 'password': password}, follow_redirects=True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logged_user(client):
|
||||
login(client)
|
||||
return client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def logged_admin(client):
|
||||
login(client, 'admin@test.com')
|
||||
return client
|
||||
Reference in New Issue
Block a user