You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
7 years ago
|
import pytest
|
||
|
import transaction
|
||
|
|
||
|
from pyramid import testing
|
||
|
|
||
|
|
||
|
APP_SETTINGS = {
|
||
|
'sqlalchemy.url': 'sqlite:///:memory:',
|
||
|
}
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope='session')
|
||
|
def app_config():
|
||
|
''' fixture for tests requiring a pyramid.testing setup '''
|
||
|
with testing.testConfig(settings=APP_SETTINGS) as config:
|
||
|
config.include('pyramid_jinja2')
|
||
|
config.include('pyramid_listing')
|
||
|
yield config
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope='session')
|
||
|
def dbsession(app_config):
|
||
|
''' fixture for testing with database connection '''
|
||
|
from ordr.models.meta import Base
|
||
|
from ordr.models import (
|
||
|
get_engine,
|
||
|
get_session_factory,
|
||
|
get_tm_session
|
||
|
)
|
||
|
|
||
|
settings = app_config.get_settings()
|
||
|
engine = get_engine(settings)
|
||
|
session_factory = get_session_factory(engine)
|
||
|
session = get_tm_session(session_factory, transaction.manager)
|
||
|
Base.metadata.create_all(engine)
|
||
|
|
||
|
yield session
|
||
|
|
||
|
transaction.abort()
|
||
|
Base.metadata.drop_all(engine)
|
||
|
|
||
|
|
||
|
def test_passing_view(dbsession):
|
||
|
from ordr.views.default import my_view
|
||
|
from ordr.models import MyModel
|
||
|
model = MyModel(name='one', value=55)
|
||
|
dbsession.add(model)
|
||
|
info = my_view(None, testing.DummyRequest(dbsession=dbsession))
|
||
|
assert info['one'].name == 'one'
|
||
|
assert info['project'] == 'Ordr'
|
||
|
|