コード例 #1
0
ファイル: test_env_helper.py プロジェクト: djangsters/agilo
    def reset_db(self, default_data=None):
        from agilo.test.functional.api import EnvironmentBuilder
        env = EnvironmentBuilder.get_testenv(self.env_key)
        from trac.db.api import _parse_db_str
        scheme, db_prop = _parse_db_str(env.get_db_url())

        if scheme != 'sqlite' and not default_data:
            return super(BetterEnvironmentStub, self).reset_db(default_data)

        env_for_transaction = env.get_trac_environment()
        if AgiloTicketSystem.is_trac_1_0():
            env_for_transaction = env

        tables = []
        if scheme != 'sqlite':
            db = self.get_db_cnx()
            @with_transaction(env_for_transaction, db)
            def implementation(db):
                cursor = db.cursor()
                cursor.execute("update system set value='9999' WHERE name='database_version'")
                db.commit()

            tables = super(BetterEnvironmentStub, self).reset_db(default_data)
        else:
            from trac import db_default
            from trac.db_default import schema
            from trac.db.sqlite_backend import _to_sql

            # our 'destroy_db'
            db = self.get_db_cnx()
            @with_transaction(env_for_transaction, db)
            def implementation(db):
                cursor = db.cursor()
                cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
                tables = cursor.fetchall()
                for table in tables:
                    cursor.execute("DROP TABLE %s" % table)

                # part of sqlite_backend's init_db
                for table in schema:
                    for stmt in _to_sql(table):
                        cursor.execute(stmt)

                # part of reset_db
                for table, cols, vals in db_default.get_data(db):
                    cursor.executemany("INSERT INTO %s (%s) VALUES (%s)"
                                       % (table, ','.join(cols),
                                          ','.join(['%s' for c in cols])),
                        vals)
                db.commit()

        if env.tester.testcase.testtype != 'unittest':
            try:
                env._upgrade_environment()
                env._setup_users_and_permissions()
            except:
                # it's possible that this has already happened
                print "Warning: Exception on post-reset_db tasks"

        return tables
コード例 #2
0
ファイル: testcase.py プロジェクト: djangsters/agilo
 def setUp(self, env_key='agilo'):
     from agilo.test.functional.api import EnvironmentBuilder
     self.env_key = env_key
     from agilo.test import test_env_helper
     test_env_helper.LAST_ENV_KEY = self.env_key
     self.super()
     testenv = EnvironmentBuilder.get_testenv(self.env_key)
     testenv.tester.set_testcase(self)
     self.teh = TestEnvHelper(enable=self.__class__.plugins, strict=self.__class__.strict, env=self.env, env_key=self.env_key)
     self.env = self.teh.get_env()
     self.teh.clear_ticket_system_field_cache()
コード例 #3
0
 def setUp(self, env_key='agilo'):
     from agilo.test.functional.api import EnvironmentBuilder
     self.env_key = env_key
     from agilo.test import test_env_helper
     test_env_helper.LAST_ENV_KEY = self.env_key
     self.super()
     testenv = EnvironmentBuilder.get_testenv(self.env_key)
     testenv.tester.set_testcase(self)
     self.teh = TestEnvHelper(enable=self.__class__.plugins,
                              strict=self.__class__.strict,
                              env=self.env,
                              env_key=self.env_key)
     self.env = self.teh.get_env()
     self.teh.clear_ticket_system_field_cache()
コード例 #4
0
ファイル: test_env_helper.py プロジェクト: djangsters/agilo
    def __init__(self, default_data=False, enable=None, env_key='agilo'):
        self.env_key = env_key
        self._destroyedInSetup = None
        from agilo.test.functional.api import EnvironmentBuilder
        testenv = EnvironmentBuilder.get_testenv(self.env_key)
        self.dburi = testenv.get_db_url()
        super(BetterEnvironmentStub, self).__init__(default_data=default_data, enable=enable)
        self.db = None

        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        for name_or_class in enable or ():
            config_key = self.normalize_configuration_key(name_or_class)
            self.config.set('components', config_key, 'enabled')
コード例 #5
0
    def __init__(self, default_data=False, enable=None, env_key='agilo'):
        self.env_key = env_key
        self._destroyedInSetup = None
        from agilo.test.functional.api import EnvironmentBuilder
        testenv = EnvironmentBuilder.get_testenv(self.env_key)
        self.dburi = testenv.get_db_url()
        super(BetterEnvironmentStub, self).__init__(default_data=default_data,
                                                    enable=enable)
        self.db = None

        if enable is not None:
            self.config.set('components', 'trac.*', 'disabled')
        for name_or_class in enable or ():
            config_key = self.normalize_configuration_key(name_or_class)
            self.config.set('components', config_key, 'enabled')
コード例 #6
0
def custom_get_dburi():
    from agilo.test.functional.api import EnvironmentBuilder
    if LAST_ENV_KEY not in EnvironmentBuilder._created_environments.keys():
        return original_get_dburi()
    testenv = EnvironmentBuilder.get_testenv(LAST_ENV_KEY)
    return testenv.get_db_url()
コード例 #7
0
    def reset_db(self, default_data=None):
        from agilo.test.functional.api import EnvironmentBuilder
        env = EnvironmentBuilder.get_testenv(self.env_key)
        from trac.db.api import _parse_db_str
        scheme, db_prop = _parse_db_str(env.get_db_url())

        if scheme != 'sqlite' and not default_data:
            return super(BetterEnvironmentStub, self).reset_db(default_data)

        env_for_transaction = env.get_trac_environment()
        if AgiloTicketSystem.is_trac_1_0():
            env_for_transaction = env

        tables = []
        if scheme != 'sqlite':
            db = self.get_db_cnx()

            @with_transaction(env_for_transaction, db)
            def implementation(db):
                cursor = db.cursor()
                cursor.execute(
                    "update system set value='9999' WHERE name='database_version'"
                )
                db.commit()

            tables = super(BetterEnvironmentStub, self).reset_db(default_data)
        else:
            from trac import db_default
            from trac.db_default import schema
            from trac.db.sqlite_backend import _to_sql

            # our 'destroy_db'
            db = self.get_db_cnx()

            @with_transaction(env_for_transaction, db)
            def implementation(db):
                cursor = db.cursor()
                cursor.execute(
                    "SELECT name FROM sqlite_master WHERE type='table'")
                tables = cursor.fetchall()
                for table in tables:
                    cursor.execute("DROP TABLE %s" % table)

                # part of sqlite_backend's init_db
                for table in schema:
                    for stmt in _to_sql(table):
                        cursor.execute(stmt)

                # part of reset_db
                for table, cols, vals in db_default.get_data(db):
                    cursor.executemany(
                        "INSERT INTO %s (%s) VALUES (%s)" %
                        (table, ','.join(cols), ','.join(['%s'
                                                          for c in cols])),
                        vals)
                db.commit()

        if env.tester.testcase.testtype != 'unittest':
            try:
                env._upgrade_environment()
                env._setup_users_and_permissions()
            except:
                # it's possible that this has already happened
                print "Warning: Exception on post-reset_db tasks"

        return tables
コード例 #8
0
 def tearDown(self):
     from agilo.test.functional.api import EnvironmentBuilder
     testenv = EnvironmentBuilder.get_testenv(self.env_key)
     testenv.tester.set_testcase(None)
     self.super()
コード例 #9
0
ファイル: testcase.py プロジェクト: djangsters/agilo
 def tearDown(self):
     from agilo.test.functional.api import EnvironmentBuilder
     testenv = EnvironmentBuilder.get_testenv(self.env_key)
     testenv.tester.set_testcase(None)
     self.super()
コード例 #10
0
ファイル: test_env_helper.py プロジェクト: djangsters/agilo
def custom_get_dburi():
    from agilo.test.functional.api import EnvironmentBuilder
    if LAST_ENV_KEY not in EnvironmentBuilder._created_environments.keys():
        return original_get_dburi()
    testenv = EnvironmentBuilder.get_testenv(LAST_ENV_KEY)
    return testenv.get_db_url()