def setUp(self): # Database tmp file. self.db_fd, self.db_path = tempfile.mkstemp() # App and test client. config = self.get_config(self.db_path) self.app = create_app(config=config, envvar=None) self.client = self.app.test_client() # App context. self.app_ctx = self.app.app_context() self.app_ctx.push() # Init database. database.init_db() # Request context. self.request_ctx = self.app.test_request_context() self.request_ctx.push() self.setup()
from inspect import isclass from flask.ext.script import Manager, Command from archive_chan import create_app, commands commands = [ 'create_user', 'update', 'remove_orphaned_files', 'remove_old_threads', 'recount_denormalized', 'sql', 'init_db' ] def add_commands(names, manager): pack = __import__('archive_chan.commands', fromlist=names) for name in commands: mod = getattr(pack, name) command = getattr(mod, 'Command') manager.add_command(name, command) app = create_app() manager = Manager(app) add_commands(commands, manager) if __name__ == "__main__": manager.run()