當前位置: 首頁>>代碼示例>>Python>>正文


Python AnnouncementSystem.upgrade_environment方法代碼示例

本文整理匯總了Python中announcer.api.AnnouncementSystem.upgrade_environment方法的典型用法代碼示例。如果您正苦於以下問題:Python AnnouncementSystem.upgrade_environment方法的具體用法?Python AnnouncementSystem.upgrade_environment怎麽用?Python AnnouncementSystem.upgrade_environment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在announcer.api.AnnouncementSystem的用法示例。


在下文中一共展示了AnnouncementSystem.upgrade_environment方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SubscriptionTestSetup

# 需要導入模塊: from announcer.api import AnnouncementSystem [as 別名]
# 或者: from announcer.api.AnnouncementSystem import upgrade_environment [as 別名]
class SubscriptionTestSetup(unittest.TestCase):
    def setUp(self):
        self.env = EnvironmentStub(enable=['trac.*'])
        self.env.path = tempfile.mkdtemp()
        self.db_mgr = DatabaseManager(self.env)
        self.db = self.env.get_db_cnx()
        # Setup current announcer db schema tables.
        self.an_sys = AnnouncementSystem(self.env)
        self.an_sys.upgrade_environment(self.db)

    def tearDown(self):
        self.db.close()
        # Really close db connections.
        self.env.shutdown()
        shutil.rmtree(self.env.path)
開發者ID:lkraav,項目名稱:trachacks,代碼行數:17,代碼來源:model.py

示例2: AnnouncementSystemSetupTestCase

# 需要導入模塊: from announcer.api import AnnouncementSystem [as 別名]
# 或者: from announcer.api.AnnouncementSystem import upgrade_environment [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


注:本文中的announcer.api.AnnouncementSystem.upgrade_environment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。