def tearDown(self): """ 测试运行之后 数据库和应用上下文在 tearDown() 方法中删除 :return: """ db.session.remove() db.drop_all() self.app_context.pop()
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 tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
def dropdb(): if prompt_bool('Drop all data?'): db.drop_all() print('Dropped database')
from flasky.Models import User, Post from flasky import db, app db.drop_all() db.create_all() user1 = User(username="******", email="*****@*****.**", password="******") db.session.add(user1) user2 = User(username="******", email="*****@*****.**", password="******") db.session.add(user2) post1 = Post(title="first post", content=" the content", user_id=1) db.session.add(post1) db.session.commit() # app.run(host="0.0.0.0", port=5000, debug=True) # print(User.query.all()) # print(Post.query.all())
def tearDown(self): db.session.remove() db.drop_all() #removes all the table after every test.