本文整理汇总了Python中announcer.api.AnnouncementSystem.get_schema_version方法的典型用法代码示例。如果您正苦于以下问题:Python AnnouncementSystem.get_schema_version方法的具体用法?Python AnnouncementSystem.get_schema_version怎么用?Python AnnouncementSystem.get_schema_version使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类announcer.api.AnnouncementSystem
的用法示例。
在下文中一共展示了AnnouncementSystem.get_schema_version方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AnnouncementSystemSetupTestCase
# 需要导入模块: from announcer.api import AnnouncementSystem [as 别名]
# 或者: from announcer.api.AnnouncementSystem import get_schema_version [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)
#.........这里部分代码省略.........