def run_scoped(app, db, client, request):
with app.app_context():
connection = db.engine.connect()
transaction = connection.begin()
options = dict(bind=connection, binds={})
session = db.create_scoped_session(options=options)
db.session = session
db.create_all()
with client:
yield
db.drop_all()
transaction.rollback()
connection.close()
session.remove()
python类drop_all()的实例源码
def setUp(self):
db.drop_all()
db.create_all()
connection = db.engine.raw_connection()
try:
c = connection.cursor()
for f in self.INIT_FILES:
script = open(
os.path.join(os.path.dirname(__file__), self.SQL_DIR, f), 'rt', encoding='utf-8-sig').read()
# print(script)
res = c.execute(script)
connection.commit()
finally:
pass
connection.close()
test_back_end.py 文件源码
项目:flask-selenium-webdriver-part-one
作者: mbithenzomo
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def setUp(self):
"""
Will be called before every test
"""
db.session.commit()
db.drop_all()
db.create_all()
# create test admin user
admin = Employee(username="admin", password="admin2016", is_admin=True)
# create test non-admin user
employee = Employee(username="test_user", password="test2016")
# save users to database
db.session.add(admin)
db.session.add(employee)
db.session.commit()
def db(request):
yield flask_db
flask_db.drop_all()
def resetdb(ctx):
from app import app, db
with app.app_context():
db.drop_all()
db.create_all()
test_client.py 文件源码
项目:circleci-demo-python-flask
作者: CircleCI-Public
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
test_basics.py 文件源码
项目:circleci-demo-python-flask
作者: CircleCI-Public
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
test_selenium.py 文件源码
项目:circleci-demo-python-flask
作者: CircleCI-Public
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def tearDownClass(cls):
if cls.client:
# stop the flask server and the browser
cls.client.get('http://localhost:5000/shutdown')
cls.client.close()
# destroy database
db.drop_all()
db.session.remove()
# remove application context
cls.app_context.pop()
test_user_model.py 文件源码
项目:circleci-demo-python-flask
作者: CircleCI-Public
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def setUp(self):
self.ctx = app.app_context()
self.ctx.push()
db.drop_all() # just in case
db.create_all()
self.client = app.test_client()
def tearDown(self):
db.drop_all()
self.ctx.pop()
def db(request, app):
"""Create test database tables"""
_db.drop_all()
# Create the tables based on the current model
_db.create_all()
user = User.create_test_user()
TestClient.test_user = user
app.test_client_class = TestClient
app.response_class = TestResponse
_db.session.commit()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDownClass(cls):
if cls.client:
# stop the flask server and the browser
cls.client.get('http://localhost:5000/shutdown')
cls.client.close()
# destroy database
db.drop_all()
db.session.remove()
# remove application context
cls.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def dropdb():
if prompt_bool(
'Are you sure you want to lose all your data'):
db.drop_all()
def tearDown(self):
"""
Drop the database tables and also remove the session
:return:
"""
db.session.remove()
db.drop_all()
def tearDown(self):
db.session.remove()
db.drop_all() # ??????????????????????????????????...
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()
def tearDownClass(cls):
if cls.client:
# stop the flask server and the browser
cls.client.get('http://localhost:5000/shutdown')
cls.client.quit()
cls.server_thread.join()
# destroy database
db.drop_all()
db.session.remove()
# remove application context
cls.app_context.pop()
def tearDown(self):
db.session.remove()
db.drop_all()
self.app_context.pop()