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


Python DatabaseManager.get_connector方法代码示例

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


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

示例1: AnnouncementSystemSetupTestCase

# 需要导入模块: from trac.db.api import DatabaseManager [as 别名]
# 或者: from trac.db.api.DatabaseManager import get_connector [as 别名]
class AnnouncementSystemSetupTestCase(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*'])
        self.env.path = tempfile.mkdtemp()
        self.db_mgr = DatabaseManager(self.env)
        self.an_sys = AnnouncementSystem(self.env)

    def tearDown(self):
        self.env.shutdown()
        shutil.rmtree(self.env.path)

    # Helpers

    def _schema_init(self, schema=None):
        # Current announcer schema is setup with enabled component anyway.
        #   Revert these changes for clean install testing.
        with self.env.db_transaction as db:
            db("DROP TABLE IF EXISTS subscriptions")
            db("DROP TABLE IF EXISTS subscription")
            db("DROP TABLE IF EXISTS subscription_attribute")
            db("DELETE FROM system WHERE name='announcer_version'")

            if schema:
                connector = self.db_mgr.get_connector()[0]
                for table in schema:
                    for stmt in connector.to_sql(table):
                        db(stmt)

    def _verify_curr_schema(self):
        self.assertFalse(self.an_sys.environment_needs_upgrade())
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("SELECT * FROM subscription_attribute")
            columns = [col[0] for col in cursor.cursor.description]
        self.assertTrue('name' not in columns)
        self.assertTrue('value' not in columns)
        self.assertEquals(
            ['id', 'sid', 'authenticated', 'class', 'realm', 'target'],
            columns
        )
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("""
                SELECT value
                  FROM system
                 WHERE name='announcer_version'
            """)
            version = int(cursor.fetchone()[0])
        self.assertEquals(db_default.schema_version, version)

    def _verify_version_unregistered(self):
        with self.env.db_query as db:
            cursor = db.cursor()
            cursor.execute("""
                SELECT value
                  FROM system
                 WHERE name='announcer_version'
            """)
            self.assertFalse(cursor.fetchone())

    def test_new_install(self):
        # Just do db table clean-up.
        self._schema_init()

        self.assertEquals(0, self.an_sys.get_schema_version())
        self.assertTrue(self.an_sys.environment_needs_upgrade())

        self.an_sys.upgrade_environment()
        self._verify_curr_schema()

    def test_upgrade_v1_to_current(self):
        # The initial db schema from r3015 - 10-Jan-2008 by Stephen Hansen.
        schema = [
            Table('subscriptions', key='id')[
                Column('id', auto_increment=True),
                Column('sid'),
                Column('enabled', type='int'),
                Column('managed', type='int'),
                Column('realm'),
                Column('category'),
                Column('rule'),
                Column('destination'),
                Column('format'),
                Index(['id']),
                Index(['realm', 'category', 'enabled']),
            ]
        ]
        self._schema_init(schema)

        # Populate tables with test data.
        with self.env.db_transaction as db:
            cursor = db.cursor()
            cursor.executemany("""
                INSERT INTO session
                       (sid,authenticated,last_visit)
                VALUES (%s,%s,%s)
            """, (('somebody', '0', '0'), ('user', '1', '0')))
            cursor.executemany("""
                INSERT INTO session_attribute
                       (sid,authenticated,name,value)
#.........这里部分代码省略.........
开发者ID:aroth-arsoft,项目名称:trac-announcer,代码行数:103,代码来源:api.py


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