当前位置: 首页>>代码示例>>Python>>正文


Python Database.truncate_tables方法代码示例

本文整理汇总了Python中model.database.Database.truncate_tables方法的典型用法代码示例。如果您正苦于以下问题:Python Database.truncate_tables方法的具体用法?Python Database.truncate_tables怎么用?Python Database.truncate_tables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.database.Database的用法示例。


在下文中一共展示了Database.truncate_tables方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestTableExistence

# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import truncate_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()
开发者ID:Zacharoo,项目名称:riot-api,代码行数:28,代码来源:test_table_existence.py

示例2: TestObjectInitialization

# 需要导入模块: from model.database import Database [as 别名]
# 或者: from model.database.Database import truncate_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    
开发者ID:Zacharoo,项目名称:riot-api,代码行数:63,代码来源:test_obj_initialization.py


注:本文中的model.database.Database.truncate_tables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。