本文整理汇总了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)
#.........这里部分代码省略.........