Ejemplo n.º 1
0
def drop_and_create_database():
    if database_exists(db.engine.url):
        drop_database(db.engine.url)
    create_database(db.engine.url)
    db.drop_all()
    db.create_all()
    db.session.commit()
 def setUp(self):
     """ Runs before each test """
     service.init_db()
     db.drop_all()  # clean up the last tests
     db.create_all()  # create new tables
     Shopcart(user_id=1, product_id=1, quantity=1, price=12.00).save()
     Shopcart(user_id=1, product_id=2, quantity=1, price=15.00).save()
     self.app = service.app.test_client()
Ejemplo n.º 3
0
def initdb():
    """initialize database"""
    
    
    
    
    db.drop_all()
    db.create_all()
Ejemplo n.º 4
0
 def setUp(self):
     """ Runs before each test """
     # service.init_db()
     db.drop_all()    # clean up the last tests
     db.create_all()  # create new tables
     Product(pid=1,pname="Athens Table", pdesc='Stupid Table', pcat="Table", pprice=20, pcond="Boxed",pinv=2, prev="", prat=5).save()
     Product(pid=2,pname="Rome Chair", pdesc='Stupid Chair', pcat="Chair", pprice=40, pcond="Boxed", pinv=2, prev="",prat=8).save()
     self.app = service.app.test_client()
Ejemplo n.º 5
0
def client(app):
    with app.app_context() as c:
        from app.model import db
        try:
            db.create_all()
            yield app.test_client()
        finally:
            db.session.remove()
            db.drop_all()
Ejemplo n.º 6
0
def build_sample_db():
    """
    Populate a small db with some example entries.
    """

    import string
    import random

    db.drop_all()
    db.create_all()

    with app.app_context():
        user_role = Role(name='user')
        super_user_role = Role(name='superuser')
        db.session.add(user_role)
        db.session.add(super_user_role)
        db.session.commit()

        test_user = user_datastore.create_user(
            name='admin',
            email='admin',
            password=hash_password('admin'),
            roles=[super_user_role, user_role])

        test_user = user_datastore.create_user(
            name='zhang',
            email='zhang',
            password=hash_password('123123'),
            roles=[user_role])

        roles = [user_role, super_user_role]
        #
        # first_names = [
        #     'Harry', 'Amelia', 'Oliver', 'Jack', 'Isabella', 'Charlie', 'Sophie', 'Mia',
        #     'Jacob', 'Thomas', 'Emily', 'Lily', 'Ava', 'Isla', 'Alfie', 'Olivia', 'Jessica',
        #     'Riley', 'William', 'James', 'Geoffrey', 'Lisa', 'Benjamin', 'Stacey', 'Lucy'
        # ]
        # last_names = [
        #     'Brown', 'Smith', 'Patel', 'Jones', 'Williams', 'Johnson', 'Taylor', 'Thomas',
        #     'Roberts', 'Khan', 'Lewis', 'Jackson', 'Clarke', 'James', 'Phillips', 'Wilson',
        #     'Ali', 'Mason', 'Mitchell', 'Rose', 'Davis', 'Davies', 'Rodriguez', 'Cox', 'Alexander'
        # ]
        #
        # for i in range(len(first_names)):
        #     tmp_email = first_names[i].lower() + "." + last_names[i].lower() + "@example.com"
        #     tmp_pass = ''.join(random.choice(string.ascii_lowercase + string.digits) for i in range(10))
        #     user_datastore.create_user(
        #         first_name=first_names[i],
        #         last_name=last_names[i],
        #         email=tmp_email,
        #         password=encrypt_password(tmp_pass),
        #         roles=[user_role, ]
        #     )
        db.session.commit()
    return
Ejemplo n.º 7
0
    def setUp(self):

        app = create_app()
        self.app = app
        self.client = app.test_client()

        db.init_app(app)
        db.app = app
        with app.app_context():    
            db.drop_all()
            db.create_all()
Ejemplo n.º 8
0
def client():
    """Create flask test client"""
    instance = app.create_app()
    instance.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
    instance.app_context().push()

    with instance.app_context():
        db.create_all()

    yield instance.test_client()

    with instance.app_context():
        db.drop_all()
Ejemplo n.º 9
0
def initdb():
    try:
        db.create_all()
    except:
        db.drop_all()
        db.create_all()
    # init some data
    try:
        # ring required
        unringed = Ring(name = "unringed")
        unringed.save()
        # data for simon
        wiki = Link("Team Wiki", "http://twiki.emccrdc.com/twiki/bin/view/ESD/Test/UsdEftTeam")
        wiki.save()
        report = Link("Weekly Report", 'http://report.emccrdc.com/mytimesheet.php?action=showts&reporter_id=177')
        report.save()
        myssh =  Ssh("MyLinux", "10.109.17.204 ", "xinming", "111111")
        myssh.save()
        rayssh =  Ssh("RayLinux", "10.32.191.173 ", "simon", "simon")
        rayssh.save()
        iohost = Type("IO HOST")
        iohost.save()
        spa = Type("SPA")
        spa.save()
        spb = Type("SPB")
        spb.save()
        vm = Type("VM")
        vm.save()
        host = Host("localhost")
        host.ring_id = unringed.id
        host.type = spa.name
        host.save()
        flash("Init database successfully.", 'successfully')
    except Exception as e:
        flash("Init database failed. %s" % e, 'error')
    return redirect(url_for("admin.index"))
Ejemplo n.º 10
0
def delete_data():
    db.drop_all()
    return "sqlite delete database  OK"
Ejemplo n.º 11
0
 def setUp(self):
     Shopcart.init_db()
     db.drop_all()    # clean up the last tests
     db.create_all()  # make our sqlalchemy tables
Ejemplo n.º 12
0
 def tearDown(self):
     with self.app.app_context():
         db.drop_all()
def initdb():
    print('were')
    db.drop_all()
    db.create_all()
Ejemplo n.º 14
0
 def setUp(self):
     # Product.init_db(app)
     db.drop_all()  # clean up the last tests
     db.create_all()  # make our sqlalchemy tables
Ejemplo n.º 15
0
 def tearDownClass(cls):
     db.session.remove()
     db.drop_all()   
Ejemplo n.º 16
0
def drop_db():
    # 删除数据库中所有的表
    db.drop_all()
    return '删除成功'
Ejemplo n.º 17
0
def drop_db():  # 删除db
    if prompt_bool('你确定删除数据库吗?'):
        db.drop_all()
Ejemplo n.º 18
0
def dropdb():
    db.drop_all()
    flash("Drop database successfully.", 'successfully')
    return redirect(url_for("admin.index"))
Ejemplo n.º 19
0
 def setUp(self):
     db.drop_all()
     db.create_all()
     create_user(self.username, self.password)
Ejemplo n.º 20
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Ejemplo n.º 21
0
 def tearDown(self):
     db.session.rollback()
     db.drop_all()
Ejemplo n.º 22
0
 def resetdatabase():  # 重置数据库
     db.drop_all(app=app)
     db.create_all(app=app)
     click.echo('Reset database, successful.')
Ejemplo n.º 23
0
def init_db():
    db.drop_all()
    db.create_all()