def create_app(config_name='dev'): global DEFAULTS_INSERTED app = Flask(__name__) config_name = os.environ.get('FLASK_CONFIG', config_name) app.config.from_object(config_by_name[config_name]) db.init_app(app) mail.init_app(app) login_manager.init_app(app) app.register_error_handler(404, page_not_found) app.register_error_handler(401, custom_401) with app.app_context(): from web.authentication import authentication app.register_blueprint(authentication, url_prefix="/") from web.app import main_routes app.register_blueprint(main_routes, url_prefix='/') # Create DB Models db.create_all() return app
def setUp(self): self.app = create_app('configtest') self.test_client = self.app.test_client() self.app_context = self.app.app_context() self.app_context.push() self.test_user_name = 'testuser' self.test_user_password = '******' db.create_all()
def setUp(self): self.app = create_app("TESTING") self.app_context = self.app.app_context() self.app_context.push() create_database(self.app.config["SQLALCHEMY_DATABASE_URI"]) db.create_all() create_dummy_data() self.client = self.app.test_client(use_cookies=True)
def setup_db(): """Create database and import Majors/Minors""" print("Clearing any pending session actions") db.session.remove() print("Dropping Tables") db.drop_all() print("Creating Tables") db.create_all() print("Committing") db.session.commit() print("Done!")
def recreate_database_and_admin(app, admin_password='******', delect_table=False): """重建数据库和新建管理员""" if delect_table is True: db.drop_all(app=app) db.create_all(app=app) db.reflect() sha1_password = '******' % ('admin', admin_password, app.config['SALT']) last_password = hashlib.sha1(sha1_password.encode('utf-8')).hexdigest() new_use = Users(UserName='******', Password=last_password, CreateDate=datetime.now()) with app.app_context(): db.session.add(new_use) db.session.commit()
def testapp(request): app = create_app('web.settings.TestConfig') client = app.test_client() db.app = app db.create_all() if getattr(request.module, "create_user", True): admin = User('admin', 'supersafepassword') db.session.add(admin) db.session.commit() def teardown(): db.session.remove() db.drop_all() request.addfinalizer(teardown) return client
def createdb(): """ Creates a database with all of the tables defined in your SQLAlchemy models """ db.create_all()
def createdb(): """Create database.""" db.create_all()
def createdb(): print app.config.get('SQLALCHEMY_DATABASE_URI') db.drop_all() db.create_all()
import sys from web import create_app from web.models import db configFile = "config" if len(sys.argv) > 1: configFile = sys.argv[1] app = create_app(configFile, debug=True) if __name__ == '__main__': # Create in the db the tables that are missing app_context = app.app_context() app_context.push() db.create_all() # start the app app.run(host='0.0.0.0', port=5000, debug=True)