示例#1
0
 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()
示例#2
0
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))
示例#3
0
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))
示例#4
0
    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()
示例#5
0
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)
示例#6
0
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()
示例#7
0
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()
示例#8
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
示例#9
0
    __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()
示例#11
0
def db_handle(db):
    db.drop_all()
    db.create_all()
示例#12
0
def init_db():
    """ Initialize the database."""
    db.drop_all()
    db.create_all()
    create_admin_users()
示例#13
0
文件: tests.py 项目: wuyu1001/guigui
 def tearDown(self):
     """
     Will be called after every test
     """
     db.session.remove()
     db.drop_all()
示例#14
0
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)
示例#15
0
def drop_db():
    """Drops the db tables."""
    db.drop_all(bind=None)
示例#16
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
示例#17
0
 def tearDown(self):
     """gets run after every test"""
     db.session.remove()
     db.drop_all()
示例#18
0
    def tearDown(self):

        db.session.remove()
        db.drop_all()
示例#19
0
def initdb(drop):
    if drop:
        db.drop_all()
    db.create_all()
    click.echo('重置資料庫')
示例#20
0
 def tearDown(self):
     db.drop_all()
示例#21
0
def schema_drop():
    db.drop_all()
    print('you had drop all tables')
示例#22
0
def init_db():
    db.drop_all()
    db.create_all()
示例#23
0
def dropdb():
    db.drop_all()