def tearDown(): """ Removes the default configurations, and in this case deletes the database data and sessions in sqlalchemy after each test """ db.session.remove() db.drop_all()
def create_db(): db.session.rollback() db.drop_all() db.create_all() if not os.path.exists(SQLALCHEMY_MIGRATE_REPO): api.create(SQLALCHEMY_MIGRATE_REPO, 'database_repository') api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) else: api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
def setUp(self): """ Sets up the default configurations, and in this case creates the database to be used """ with self.app.test_client(): db.session.close() db.drop_all() db.create_all() self.populate_db()
def create_db(test_app): try: db.create_all(app=test_app) except: sqlalchemy_utils.create_database(TestConfig.SQLALCHEMY_DATABASE_URI) db.create_all(app=test_app) yield db #db.session.close() db.session.remove() db.drop_all(app=test_app)
def init_database(): # Create the database and the database table db.create_all() # Insert user data user1 = User(username='******', plaintext_password='******') user2 = User(email='anotheruser', plaintext_password='******') db.session.add(user1) db.session.add(user2) # Commit the changes for the users db.session.commit() yield db # this is where the testing happens! db.drop_all()
def create_populate_db(): from models import Account, Milestone, Timeline # Creation de la database db.drop_all() db.create_all() # Creation des comptes livretA = Account('Livret A', '3900') livretJeune = Account('Livret Jeune', '1600') db.session.add(livretA) db.session.add(livretJeune) june = Timeline(datetime.datetime.strptime('01 06 2015', "%d %m %Y").date(), '350') july = Timeline(datetime.datetime.strptime('01 07 2015', "%d %m %Y").date(), '330') august = Timeline(datetime.datetime.strptime('01 08 2015', "%d %m %Y").date(), '1000') september = Timeline(datetime.datetime.strptime('01 09 2015', "%d %m %Y").date(), '1500') october = Timeline(datetime.datetime.strptime('01 10 2015', "%d %m %Y").date(), '2500') november = Timeline(datetime.datetime.strptime('01 11 2015', "%d %m %Y").date(), '3100') december = Timeline(datetime.datetime.strptime('01 12 2015', "%d %m %Y").date(), '5500') db.session.add(june) db.session.add(july) db.session.add(august) db.session.add(september) db.session.add(october) db.session.add(november) db.session.add(december) # Creation des milestones mille = Milestone('1000 !!', '1000') cinqmille = Milestone('5000 !!', '5000') dixmille = Milestone('10 000 !!', '10000') vingtmille = Milestone('20 000 !!', '20000') cinquantemille = Milestone('50 000 !!', '50000') centmille = Milestone('100 000 !!', '100000') db.session.add(mille) db.session.add(cinqmille) db.session.add(dixmille) db.session.add(vingtmille) db.session.add(cinquantemille) db.session.add(centmille) #commit db.session.commit()
def tearDown(self): db.session.remove() db.drop_all()
__tablename__='oplog' id=db.Column(db.Integer,primary_key=True) # admin_id=db.Column(db.Integer,db.ForeignKey("admin.id")) admin_id=db.Column(db.Integer) ip=db.Column(db.String(100)) reason=db.Column(db.String(600)) addtime=db.Column(db.DATETIME,index=True,default=datetime.datetime.now) def __repr__(self): return "<oplog %s>"%self.id def add_log(log): db.session.add(log) db.session.commit() if __name__=='__main__': # pass # 创建表 db.drop_all(User) db.create_all(User) # from werkzeug.security import generate_password_hash # role=Admin( # # name='李不搭', # pwd=generate_password_hash('zslswmz'), # is_super=1, # # ) # db.session.add(role) # db.session.commit() # #
def dropdb(): if prompt_bool("Are you sure you want to lose all your data"): db.drop_all()
def db_handle(db): db.drop_all() db.create_all()
def init_db(): """ Initialize the database.""" db.drop_all() db.create_all() create_admin_users()
def tearDown(self): """ Will be called after every test """ db.session.remove() db.drop_all()
from myapp import app, db from myapp.main.models import User, Role import os def db_handle(db): db.drop_all() db.create_all() if __name__ == '__main__': db.drop_all() db.create_all() Role.init_roles() User.create_admin() app.run(debug=True)
def drop_db(): """Drops the db tables.""" db.drop_all(bind=None)
def tearDown(self): db.session.remove() db.drop_all() self.app_context.pop()
def tearDown(self): """gets run after every test""" db.session.remove() db.drop_all()
def initdb(drop): if drop: db.drop_all() db.create_all() click.echo('重置資料庫')
def tearDown(self): db.drop_all()
def schema_drop(): db.drop_all() print('you had drop all tables')
def init_db(): db.drop_all() db.create_all()
def dropdb(): db.drop_all()