本文整理汇总了Python中fixture.SQLAlchemyFixture.data方法的典型用法代码示例。如果您正苦于以下问题:Python SQLAlchemyFixture.data方法的具体用法?Python SQLAlchemyFixture.data怎么用?Python SQLAlchemyFixture.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fixture.SQLAlchemyFixture
的用法示例。
在下文中一共展示了SQLAlchemyFixture.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_app
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def setup_app(command, conf, vars):
"""Place any commands to setup tracking here"""
load_environment(conf.global_conf, conf.local_conf)
filename = os.path.split(conf.filename)[-1]
if filename == 'test.ini':
# Permanently drop any existing tables
log.info("Dropping existing tables...")
meta.Base.metadata.drop_all(bind=meta.engine, checkfirst=True)
log.info("Creating tables...")
# Create the tables if they don't already exist
meta.Base.metadata.create_all(bind=meta.engine)
log.info("Successfully set up.")
if filename == 'development.ini':
# load sample data during setup-app
db = SQLAlchemyFixture(
env=model, style=NamedDataStyle(),
engine=meta.engine)
data = db.data(PageviewsData)
log.info("Loading sample data...")
data.setup()
log.info("Successfully set up.")
示例2: TestListView
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class TestListView(TestCase):
"""Tests for DetailView."""
urls = 'tests.integration.views.generic.urls'
def setUp(self):
setup_environment()
self.fixture = SQLAlchemyFixture(
env=models,
session=session,
style=NamedDataStyle(),
)
def test_list_view(self):
"""Test the list view."""
with self.fixture.data(fixtures.PersonData) as data:
response = self.client.get('/people/')
self.assertEqual(response.status_code, 200)
self.assertIn(data.PersonData.John.name, response.content)
def test_list_view_allow_empty(self):
"""Test getting an empty list with allow_empty = True."""
response = self.client.get('/people/')
self.assertEqual(response.status_code, 200)
def test_list_view_404(self):
"""Test getting an empty list with allow_empty = False."""
response = self.client.get('/non_empty_people/')
self.assertEqual(response.status_code, 404)
示例3: install
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def install(app, *args):
engine = m.create_tables(app)
db = SQLAlchemyFixture(env=m, style=NamedDataStyle(), engine=engine)
data = db.data(*args)
data.setup()
db.dispose()
return data
示例4: test_fixture_can_be_disposed
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def test_fixture_can_be_disposed():
if sa_major < 0.5:
from sqlalchemy.exceptions import InvalidRequestError
else:
from sqlalchemy.exc import InvalidRequestError
engine = create_engine(conf.LITE_DSN)
metadata.bind = engine
metadata.create_all()
Session = get_transactional_session()
session = Session()
fixture = SQLAlchemyFixture(
env={'CategoryData':Category},
engine=metadata.bind
)
class CategoryData(DataSet):
class cars:
name = 'cars'
class free_stuff:
name = 'get free stuff'
clear_mappers()
mapper(Category, categories)
data = fixture.data(CategoryData)
data.setup()
data.teardown()
fixture.dispose()
# cannot use fixture anymore :
try:
data.setup()
except InvalidRequestError:
pass
else:
assert False, "data.setup() did not raise InvalidRequestError after connection was disposed"
# a new instance of everything is needed :
metadata.create_all()
fixture = SQLAlchemyFixture(
env={'CategoryData':Category},
engine=metadata.bind
)
data = fixture.data(CategoryData)
data.setup()
data.teardown()
示例5: setUp
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def setUp(self):
self.app = create_app('config/test.ini').test_client()
init_db()
# TODO move this to the proper place in the code
dbfixture = SQLAlchemyFixture(
env={'UserData': User},
engine=dailylog.db.engine)
self.data = dbfixture.data(UserData)
self.data.setup()
示例6: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.dbfixture = SQLAlchemyFixture(engine=get_engine(),
env={'TreeNodeData': TreeNode})
self.data = self.dbfixture.data(TreeNodeData)
self.data.setup()
self.addCleanup(self.data.teardown)
示例7: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env={'MpProviderData': Provider})
self.data = self.dbfixture.data(MpProviderData)
self.data.setup()
self.addCleanup(self.data.teardown)
示例8: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env={'AssetInfoData': AssetInfoModel})
self.data = self.dbfixture.data(AssetInfoData)
self.data.setup()
self.addCleanup(self.data.teardown)
示例9: setUp
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
def setUp(self):
db.create_all()
fixture = SQLAlchemyFixture( env=models,
style=TrimmedNameStyle(suffix="Data"),
session=db.session)
try:
self.data = fixture.data(*self.fixtures)
except TypeError:
raise Error('You need overide "fixtures = None" with the name of some real fixtures')
self.data.setup()
示例10: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.session = get_session()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env=dict(UserData=UserHstore)
)
self.data = self.dbfixture.data(UserData)
self.data.setup()
self.addCleanup(self.data.teardown)
示例11: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.engine = db_api.get_engine()
self.engine.connect()
self.dbfixture = SQLAlchemyFixture(engine=self.engine, env={"StoreStateMock": StoreState})
self.data = self.dbfixture.data(StoreStateMock)
self.session = db_api.get_session()
BASE.metadata.create_all(bind=self.engine)
self.data.setup()
self.addCleanup(self.data.teardown)
示例12: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env={'AssetConsumeInfoData': AssetConsumeInfoModel})
self.data = self.dbfixture.data(AssetConsumeInfoData)
BASE.metadata.create_all(get_engine())
self.data.setup()
self.addCleanup(self.data.teardown)
示例13: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env={'DeviceStateData': DeviceState})
self.data = self.dbfixture.data(DeviceStateData)
BASE.metadata.create_all(get_engine())
self.data.setup()
self.addCleanup(self.data.teardown)
示例14: DBFixture
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class DBFixture(fixtures.Fixture):
def setUp(self):
super(DBFixture, self).setUp()
print get_engine()
self.dbfixture = SQLAlchemyFixture(
engine=get_engine(),
env={'InOutData': InOutReason})
self.data = self.dbfixture.data(InOutData)
self.data.setup()
self.addCleanup(self.data.teardown)
示例15: TestCollidingSessions
# 需要导入模块: from fixture import SQLAlchemyFixture [as 别名]
# 或者: from fixture.SQLAlchemyFixture import data [as 别名]
class TestCollidingSessions(unittest.TestCase):
class CategoryData(DataSet):
class cars:
name = 'cars'
class free_stuff:
name = 'get free stuff'
def setUp(self):
self.engine = create_engine(conf.LITE_DSN)
# self.conn = self.engine.connect()
metadata.bind = self.engine
# metadata.bind.echo = True
metadata.create_all()
# metadata.bind.echo = False
self.ScopedSession = scoped_session(get_transactional_session())
self.session = self.ScopedSession()
self.fixture = SQLAlchemyFixture(
env={'CategoryData':Category},
engine=metadata.bind
)
clear_mappers()
mapper(Category, categories)
def tearDown(self):
metadata.drop_all()
self.session.close()
@attr(functional=1)
def test_setup_then_teardown(self):
eq_(self.session.query(Category).all(), [])
data = self.fixture.data(self.CategoryData)
data.setup()
clear_session(self.session)
cats = self.session.query(Category).order_by('name').all()
eq_(cats[0].name, 'cars')
eq_(cats[1].name, 'get free stuff')
# simulate the application running into some kind of error:
new_cat = Category()
new_cat.name = "doomed to non-existance"
save_session(self.session, new_cat)
self.session.rollback()
self.ScopedSession.remove()
data.teardown()
clear_session(self.session)
print [(c.id, c.name) for c in self.session.query(Category).all()]