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
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()
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')
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()
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
def start(self): if not self.super(): return False trac_env = self._trac_functional_test_environment trac_env.tester = trac_env.build_tester() trac_env.tester.url = trac_env.url return True def destroy(self): self.super() self._trac_functional_test_environment.destroy() def environment_information(self): first_env_info = self.super() second_env_info = self._trac_functional_test_environment.environment_information( ) return ' -- '.join([first_env_info, second_env_info]) def get_key(cls): return 'agilo_multi' get_key = classmethod(get_key) # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment( MultiEnvironmentFunctionalTestEnvironment.get_key(), MultiEnvironmentFunctionalTestEnvironment)
def stop_windmill(self): # The Firefox test wrapper currently can't kill the browser (on OS X) # after a testrun -- see http://trac.getwindmill.com/ticket/313 if self.is_windmill_initialized(): try: teardown(self.windmill_shell) except (ValueError, AssertionError), exception: # Mozrunner mac has a bug in the teardown code that will spit this out quite regulary # I swallow this exception here because the global exception handler throws away the test # output if this exception gets through which can easily make the entire test run unusable # This should be solved by mozrunner v2 in windmill 1.4 or 1.5 # TODO: log the exception pass self._windmill_initialized = False def disable_windmill_console_log_spam(self): # Windmill overwrites the root loggers level if present - so we feed it whatever was configured before # See http://trac.getwindmill.com/ticket/314 # See <windmill>/bin/admin_lib.py windmill.settings['CONSOLE_LOG_LEVEL'] = 'ERROR' # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment(AgiloFunctionalTestEnvironment.get_key(), AgiloFunctionalTestEnvironment)
proc_args.append(self.envdir) return proc_args def _start_standalone_tracd(self): "Start a standalone tracd and return its pid." if 'FIGLEAF' in os.environ: exe = os.environ['FIGLEAF'] else: exe = sys.executable proc_args = self._get_process_arguments() #print 'starting server', exe, ' '.join(proc_args) server = Popen([exe] + proc_args, stdout=self.logfile, stderr=self.logfile, close_fds=close_fds, cwd=self.command_cwd) return server.pid def _upgrade_environment(self): # Upgrading the environment is not necessary for trac but for all # plugins which need to do some database modifications. # '--no-backup' is important if you don't use sqlite. self._tracadmin('upgrade', '--no-backup') # ------------------------------------------------------------------------- # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment(TracFunctionalTestEnvironment.get_key(), TracFunctionalTestEnvironment)
def tearDown(self): from agilo.test.functional.api import EnvironmentBuilder testenv = EnvironmentBuilder.get_testenv(self.env_key) testenv.tester.set_testcase(None) self.super()
return args def start(self): if not self.super(): return False trac_env = self._trac_functional_test_environment trac_env.tester = trac_env.build_tester() trac_env.tester.url = trac_env.url return True def destroy(self): self.super() self._trac_functional_test_environment.destroy() def environment_information(self): first_env_info = self.super() second_env_info = self._trac_functional_test_environment.environment_information() return ' -- '.join([first_env_info, second_env_info]) def get_key(cls): return 'agilo_multi' get_key = classmethod(get_key) # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment(MultiEnvironmentFunctionalTestEnvironment.get_key(), MultiEnvironmentFunctionalTestEnvironment)
# Then start windmill and the browser self.windmill_shell = setup() self.windmill_shell['start_' + self.windmill_browser]() def stop_windmill(self): # The Firefox test wrapper currently can't kill the browser (on OS X) # after a testrun -- see http://trac.getwindmill.com/ticket/313 if self.is_windmill_initialized(): try: teardown(self.windmill_shell) except (ValueError, AssertionError), exception: # Mozrunner mac has a bug in the teardown code that will spit this out quite regulary # I swallow this exception here because the global exception handler throws away the test # output if this exception gets through which can easily make the entire test run unusable # This should be solved by mozrunner v2 in windmill 1.4 or 1.5 # TODO: log the exception pass self._windmill_initialized = False def disable_windmill_console_log_spam(self): # Windmill overwrites the root loggers level if present - so we feed it whatever was configured before # See http://trac.getwindmill.com/ticket/314 # See <windmill>/bin/admin_lib.py windmill.settings['CONSOLE_LOG_LEVEL'] = 'ERROR' # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment( AgiloFunctionalTestEnvironment.get_key(), AgiloFunctionalTestEnvironment)
return proc_args def _start_standalone_tracd(self): "Start a standalone tracd and return its pid." if 'FIGLEAF' in os.environ: exe = os.environ['FIGLEAF'] else: exe = sys.executable proc_args = self._get_process_arguments() #print 'starting server', exe, ' '.join(proc_args) server = Popen([exe] + proc_args, stdout=self.logfile, stderr=self.logfile, close_fds=close_fds, cwd=self.command_cwd) return server.pid def _upgrade_environment(self): # Upgrading the environment is not necessary for trac but for all # plugins which need to do some database modifications. # '--no-backup' is important if you don't use sqlite. self._tracadmin('upgrade', '--no-backup') # ------------------------------------------------------------------------- # Register this module with the EnvironmentBuilder from agilo.test.functional.api import EnvironmentBuilder EnvironmentBuilder.register_environment( TracFunctionalTestEnvironment.get_key(), TracFunctionalTestEnvironment)