我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用app.db.drop_all()。
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()
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()
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()
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 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 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 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.rollback() db.session.remove() # db.drop_all()
def drop_tables(): if prompt_bool('Are you REALLY sure? You will loose all data!'): db.drop_all()
def dropdb(): if prompt_bool( "Are you sure you want to drop the database?"): db.drop_all() print "Database has been dropped"
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() # ??app????
def tearDown(self): db.session.remove() db.drop_all()
def tearDown(self): """ Will be called after every test """ db.session.remove() db.drop_all()
def tearDown(self): db.session.remove() # Refresh db db.drop_all() self.app_context.pop()
def drop_all(): """Drop all the db tables.""" db.drop_all()
def recreate_db(): """ Recreates a local database. You probably should not use this on production. """ db.drop_all() db.create_all() db.session.commit()
def tearDown(self) : db.session.remove() db.drop_all() self.app_context.pop()
def drop_table(): """ Drops the table """ if input('Sure? [y/n]') == 'y': db.drop_all() print('Table dropped.') else: print('Bad choice. Bye!')
def tearDown(self): with self.app_context: db.session.remove() db.drop_all() self.app_context.pop()
def init(): """ Initialize the db. """ db.drop_all() db.create_all() print('Droppped and created db')