def create(): """ Creates database tables from sqlalchemy models """ db.create_all() populate() db.session.commit()
def create_app(Config): # 实例化Flask app = Flask(__name__) # 导入配置文件 app.config.from_object(Config) register_blueprint(app) moment.init_app(app) csrf.init_app(app) login_manager.init_app(app) login_manager.session_protection = 'strong' login_manager.login_view = 'Web.login' login_manager.login_message = '请先登录哦!' @login_manager.user_loader def load_user(user_id): return User.query.filter(User.uid == user_id).first() db.init_app(app) with app.app_context(): # db.drop_all() db.create_all() # BlogInfo.insert_blog_info() # User.insert_admin('*****@*****.**','huzhipeng','123456') # ArticleClass.insert_class() # BlogView.insert_view() return app
def setUp(self): """Set up the test client.""" self.app = app.test_client() db.create_all() user = User("testuser") user.hash_password("testpassword") db.session.add(user) db.session.commit()
def create_app(): app = Flask(__name__) app.register_blueprint(users) app.config["SQLALCHEMY_DATABASE_URI"] = config.DATABASE_CONNECTION_URI app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False app.app_context().push() db.init_app(app) db.create_all() return app
def setUp(self): # setup test environment configuration app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test_buckects.db' self.app = app.test_client() db.create_all() self.user = UserStore() print( self.user.create_user(name="josiah", username="******", email="*****@*****.**", password_hash="jacob"))
def create_app(): app = Flask(__name__) app.config.from_object(os.environ.get('FLASK_CONFIG') or 'config') db.init_app(app) with app.app_context(): db.create_all() app.register_blueprint(users) @app.route('/') def index(): return 'Welcome to Microblog by vaugusti !!!' return app
def setUp(self): app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['DEBUG'] = False app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format( user="******", pw="admin", url="127.0.0.1:5432", db="cryptocartera-test") self.app = app.test_client() with app.app_context(): # db.drop_all() db.create_all() moneda = Moneda(moneda="BTC") db.session.add(moneda) db.session.commit()
def setUp(self): # setup test environment configuration app.config['TESTING'] = True app.config['WTF_CSRF_ENABLED'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test_buckects_enpoints.db' self.client = app.test_client() self.u = UserStore() self.user = dict(name="josiah", username="******", email="*****@*****.**", password_hash="jacob") self.bucket = dict(bucket_name="Trip to Mars", bucket_description="test", user_id=1) self.item = dict(item_name="Swim", item_status="test item", due_date="pending", bucket_id=1) db.create_all() self.headers = {"Content-Type": "application/json"} self.response = self.client.post( '/api/v01/user/', data=json.dumps(self.user))
def create(): """ Creates database tables from sqlalchemy models """ db.create_all() populate()
def init_db(): print("creating database") db.create_all() print(db) print("database created")