You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
Python
54 lines
1.2 KiB
Python
7 years ago
|
from apistar.frameworks.wsgi import WSGIApp
|
||
|
from apistar.backends.sqlalchemy_backend import SQLAlchemyBackend, get_session
|
||
|
|
||
|
import pytest
|
||
|
|
||
|
from cookie_api.models import Base
|
||
|
from cookie_api.renders import JSONRenderer
|
||
|
from cookie_api.app import commands, routes, components
|
||
|
|
||
|
settings = {
|
||
|
'DATABASE': {
|
||
|
'URL': 'postgresql://apistar:local@localhost/test_cookie_api',
|
||
|
'METADATA': Base.metadata
|
||
|
},
|
||
|
'RENDERERS': [JSONRenderer()],
|
||
|
'JWT': {
|
||
|
'SECRET': 'thisisasecret'
|
||
|
}
|
||
|
}
|
||
|
|
||
|
backend = SQLAlchemyBackend(settings)
|
||
|
|
||
|
|
||
|
@pytest.fixture(autouse=True)
|
||
|
def create_db():
|
||
|
Base.metadata.create_all(backend.engine)
|
||
|
|
||
|
yield
|
||
|
|
||
|
Base.metadata.drop_all(backend.engine)
|
||
|
|
||
|
|
||
|
@pytest.fixture(name='rb_session')
|
||
|
def db_session_fixure():
|
||
|
"Returns a SQLAlchemy session that autorolls back"
|
||
|
session = backend.Session()
|
||
|
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 WSGIApp(settings=settings,
|
||
|
commands=commands,
|
||
|
components=components,
|
||
|
routes=routes)
|