import pytest from sqlalchemy import create_engine from apistar_jwt import JWT from cookie_api.app import application_factory from cookie_api.util import SQLAlchemySession, DBSession from cookie_api.models import Base test_engine = create_engine('postgresql://apistar:local@localhost/test_cookie_api') test_components = [ SQLAlchemySession(engine=test_engine), JWT({ 'JWT_USER_ID': 'sub', 'JWT_SECRET': 'thisisasecret', }), ] @pytest.fixture(autouse=True) def create_db(): Base.metadata.create_all(test_engine) yield Base.metadata.drop_all(test_engine) @pytest.fixture(name='rb_session') def db_session_fixure(): "Returns a SQLAlchemy session that autorolls back" DBSession.configure(bind=test_engine) session = DBSession() try: yield session session.rollback() except: session.rollback() raise finally: session.close() @pytest.fixture(name='app', scope='session') def apistar_app_fixture(): """Returns a session scoped WSGIApp instance""" return application_factory(components=test_components)