39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
os.environ['FLASK_CONFIG'] = 'TestingConfig'
|
|
|
|
from app import create_app, db
|
|
from app.config import TestingConfig
|
|
from app.models import Profile, User
|
|
|
|
|
|
@pytest.fixture
|
|
def app(monkeypatch):
|
|
monkeypatch.setattr(TestingConfig, 'SQLALCHEMY_DATABASE_URI', 'sqlite:///:memory:')
|
|
monkeypatch.setattr(TestingConfig, 'WTF_CSRF_ENABLED', False, raising=False)
|
|
application = create_app()
|
|
with application.app_context():
|
|
db.create_all()
|
|
db.session.add_all([
|
|
User(id=1, username='fixture', password_hash='unused', profile=Profile(timezone='Australia/Sydney')),
|
|
User(id=2, username='other', password_hash='unused', profile=Profile(timezone='UTC')),
|
|
])
|
|
db.session.commit()
|
|
yield application
|
|
db.session.remove()
|
|
db.drop_all()
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app):
|
|
client = app.test_client()
|
|
with client.session_transaction() as session:
|
|
session['_user_id'] = '1'
|
|
session['_fresh'] = True
|
|
return client
|