本文整理匯總了Python中model.database.Database.make_tables方法的典型用法代碼示例。如果您正苦於以下問題:Python Database.make_tables方法的具體用法?Python Database.make_tables怎麽用?Python Database.make_tables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.database.Database
的用法示例。
在下文中一共展示了Database.make_tables方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestTableExistence
# 需要導入模塊: from model.database import Database [as 別名]
# 或者: from model.database.Database import make_tables [as 別名]
class TestTableExistence(unittest.TestCase):
@classmethod
def setUpClass(self):
self.db = Database('TEST')
self.db.make_tables()
@classmethod
def tearDownClass(self):
self.db.destroy_tables()
def tearDown(self):
self.db.truncate_tables()
def test_when_all_tables_exist(self):
assert 'game_stats' in self.db.Meta.tables.keys()
assert 'game' in self.db.Meta.tables.keys()
assert 'summoner' in self.db.Meta.tables.keys()
assert 'summoner_name' in self.db.Meta.tables.keys()
def test_all_tables_have_rigth_columns(self):
t = TableTester(self.db)
test = t.has_next_table()
while test:
test()
test = t.has_next_table()
示例2: main
# 需要導入模塊: from model.database import Database [as 別名]
# 或者: from model.database.Database import make_tables [as 別名]
def main():
db = Database(mode='PROD', echo=True)
if not db.has_tables():
db.make_tables()
with open('.smurfs.txt') as f:
for line in f:
fetch_and_store_summoner(line.strip(), db)
session = db.SessionMaker()
print(session.query(GameStats, GameStats.champion).all())
示例3: TestObjectInitialization
# 需要導入模塊: from model.database import Database [as 別名]
# 或者: from model.database.Database import make_tables [as 別名]
class TestObjectInitialization(unittest.TestCase):
@classmethod
def setUpClass(self):
self.db = Database()
self.db.make_tables()
@classmethod
def tearDownClass(self):
self.db.destroy_tables()
def tearDown(self):
self.db.truncate_tables()
def test_when_game_is_made(self):
session = self.db.SessionMaker()
def query_for_game(session):
return session.query(Game).first()
expected = add_a_game(session)
observed = query_for_game(session)
session.close()
assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(observed, expected)
def test_when_game_stats_is_made(self):
session = self.db.SessionMaker()
def query_for_game_stats():
return session.query(GameStats).filter_by(summoner_name='Bjerson').first()
expected = add_game_stats(session)
observed = query_for_game_stats()
session.close()
assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(observed, expected)
def test_when_summoner_is_made(self):
session = self.db.SessionMaker()
def query_for_summoner():
return session.query(Summoner).first()
expected = add_a_summoner(session)
observed = query_for_summoner()
session.close()
assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(observed, expected)
def test_when_summoner_name_is_made(self):
session = self.db.SessionMaker()
def query_for_summoner_name():
return session.query(SummonerName).first()
expected = add_a_summoner_name(session)
observed = query_for_summoner_name()
session.close()
assert expected is observed, 'Observed:\t{0}\nExpected:\t{1}'.format(observed, expected)
def test_when_they_work_together(self):
pass