def setUp(self): app = create_app('testing') self.app_context = app.app_context() self.app_context.push() self.client = app.test_client() db.create_all()
def setUp(self): self.app = Flask(__name__) #sqlalchemy connect database basedir = os.path.abspath(os.path.dirname(__file__)) self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data-test.sqlite') self.app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True self.app.config['FLASKY_ADMIN'] = '*****@*****.**' db.create_all() Role.insert_roles()
def setUp(self): """ 测试之前运行,尝试创建一个测试环境,尽量与正常运行应用所需环境一致 :return: """ self.app = create_app('testing') # 使用测试配置创建应用 self.app_context = self.app.app_context() # 激活上下文 self.app_context.push() db.create_all()
def init_data(): from fake import users, posts, comments, follows from flasky import db db.drop_all() db.create_all() users() posts() comments() # follows() return 'data init successfully'
def setUp(self): self.app = Flask(__name__) #sqlalchemy connect database self.app.config['SECRET_KEY'] = 'hard to guess string' TESTING = True basedir = os.path.abspath(os.path.dirname(__file__)) self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'data-test.sqlite') self.app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True self.app.config['FLASKY_ADMIN'] = '*****@*****.**' WTF_CSRF_ENABLED = False db.create_all() Role.insert_roles() self.client = self.app.test_client(use_cookies=True)
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
from flasky import db from flasky import Role, User #db.drop_all() db.create_all() # 创建角色 role_admin = Role(name = 'Admin') role_mod = Role(name = 'Moderator') role_user = Role(name = 'User') user_zhao = User(username= '******', role = role_admin) user_susan = User(username = '******', role = role_mod) user_david = User(username = '******', role = role_user) db.session.add_all([role_admin, role_mod, role_user, user_david, user_susan,user_zhao]) db.session.commit() print(role_admin.id)
def initdb(): db.create_all() db.session.add(User(username='******', email='*****@*****.**', password='******')) db.session.commit() print('Initialized the database')
# from flasky.flaskr import flasky, init_db from flasky.todo import todo from flasky.client import client from flasky import db from flasky.models import TodoList,User from flasky.login import author from flask_cors import CORS CORS(app) # app.register_blueprint(flasky) app.register_blueprint(todo, url_prefix='/todo') app.register_blueprint(author,url_prefix='/author') # app.register_blueprint(client, url_prefix='/client') db.create_all() todo1 = TodoList(id=1, task=u"build an API", user='******') todo2 = TodoList(id=2, task=u'?????', user='******') todo3 = TodoList(id=3, task=u'profit!', user='******') # db.session.add(User(id=1, username=u"admin", passwordhash=u"admin")) # db.session.add(User(id=2, username=u"guest", passwordhash=u"guest")) # # # db.session.add(todo1) # db.session.add(todo2) # db.session.add(todo3) # db.session.commit() app.run(debug=True)
def setUp(self): app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'sqlite://' #ensures that we use a different database from the one used during development db.create_all( ) #since for unit tests, we are going to always start from an empty database, then we can use the db.create_all() method from