53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""
|
|
Shared pytest fixtures.
|
|
Tests run against SQLite in-memory — no Docker required.
|
|
"""
|
|
import os
|
|
import pytest
|
|
|
|
os.environ.setdefault("DATABASE_URL", "sqlite:///:memory:")
|
|
os.environ.setdefault("API_KEY", "test-key")
|
|
|
|
from app import create_app
|
|
from app.extensions import db as _db
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def app():
|
|
application = create_app()
|
|
application.config.update(
|
|
TESTING=True,
|
|
SQLALCHEMY_DATABASE_URI="sqlite:///:memory:",
|
|
)
|
|
with application.app_context():
|
|
_db.create_all()
|
|
# Seed instruments
|
|
from app.models import Instrument
|
|
for name in ("banjo", "fiddle"):
|
|
if not _db.session.query(Instrument).filter_by(name=name).first():
|
|
_db.session.add(Instrument(name=name))
|
|
_db.session.commit()
|
|
yield application
|
|
_db.drop_all()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(app):
|
|
return app.test_client()
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def clean_db(app):
|
|
with app.app_context():
|
|
yield
|
|
_db.session.rollback()
|
|
from app.models import (TuneByInstrumentNote, TuneByInstrument,
|
|
Reference, TuneNote, Tune, Source, Musician, Tuning)
|
|
for model in (TuneByInstrumentNote, Reference, TuneNote,
|
|
TuneByInstrument, Tune, Source, Musician, Tuning):
|
|
_db.session.query(model).delete()
|
|
_db.session.commit()
|
|
|
|
|
|
AUTH = {"X-API-Key": "test-key"}
|
|
BAD_AUTH = {"X-API-Key": "wrong-key"}
|