Beispiel #1
0
 def setUp(self):
     self.app = app.test_client()
     self.app_context = app.app_context()
     self.app_context.push()
     db.drop_all()
     db.create_all()
     self.admin_role = self._create_admin_role()
Beispiel #2
0
def create_user():
    db.drop_all()
    db.create_all()

    user = User(name=USERNAME, email='*****@*****.**', password='******')
    db.session.add(user)
    db.session.commit()
Beispiel #3
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    user = User(username='******', email='*****@*****.**', password='******')
    user.save()
Beispiel #4
0
def init_data():
    from imports import (
            Widget,Article,Page,
            User,Setting,Type,
            Template,Tag,Role,
            Category,Block,Profile,
            ContactMessage)
    """Fish data for project"""
    if prompt_bool('Do you want to kill your db?'):
        if squ.database_exists(db.engine.url):
            squ.drop_database(db.engine.url)
    try:
        db.drop_all()
    except:
        pass
    try:
        squ.create_database(db.engine.url)
        db.create_all()
    except:
        pass

    user = User.query.filter(User.email=='*****@*****.**').first()
    if user is None:
       user = User(username='******', email='*****@*****.**', password='******')
    user.save()
Beispiel #5
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    admin = User(
        username=app.config["ADMIN_USERNAME"], email=app.config["ADMIN_EMAIL"], password=app.config["ADMIN_PASSWORD"]
    )
    admin.save()
def setup():
    db.drop_all()
    db.create_all()
    fake_users = [
        User('xiaoming', '*****@*****.**'),
        User('dongwweiming', '*****@*****.**'),
        User('admin', '*****@*****.**')
    ]
    db.session.add_all(fake_users)
    db.session.commit()
Beispiel #7
0
def init_data():
    """Fish data for project"""
    if prompt_bool('Do you want to kill your db?'):
        db.drop_all()
    try:
       db.create_all()
    except:
        pass

    user = User.query.filter(User.email=='*****@*****.**').first()
    if user is None:
       user = User(username='******', email='*****@*****.**', password='******')
    user.save()
Beispiel #8
0
def init_data():
    """Fish data for project"""
    if prompt_bool('Do you want to kill your db?'):
    try:
        db.drop_all()
    except:
        pass
    try:
        db.create_all()
    except:
        pass

manager.add_command('shell', Shell(make_context=lambda:{'app': app, 'db': db}))


if __name__ == '__main__':
    manager.add_command('clean',Clean())
    manager.add_command('urls',ShowUrls())
    manager.add_command('mrbob',mrbob_manager)
    manager.run()
Beispiel #9
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    # Init/reset data.

    demo = Usr(
            name=u'demo', 
            email=u'*****@*****.**', 
            password=u'123456', 
            role_id=USER,
            status_id=ACTIVE,
            user_detail=UserDetail(
                age=10,
                url=u'http://demo.example.com', 
                deposit=100.00,
                location=u'Hangzhou', 
                bio=u'Demo Guy is ... hmm ... just a demo guy.'),
            )
    admin = Usr(
            name=u'admin', 
            email=u'*****@*****.**', 
            password=u'123456', 
            role_id=ADMIN,
            status_id=ACTIVE,
            user_detail=UserDetail(
                age=10,
                url=u'http://admin.example.com', 
                deposit=100.00,
                location=u'Hangzhou', 
                bio=u'admin Guy is ... hmm ... just a admin guy.'),
            )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Beispiel #10
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
app = Flask(__name__)
app.config.from_object('config')
app.config['DATABASE_QUERY_TIMEOUT'] = 0.0001
app.config['SQLALCHEMY_RECORD_QUERIES'] = True
db.init_app(app)

formatter = logging.Formatter(
    "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler = RotatingFileHandler('slow_query.log', maxBytes=10000, backupCount=10)
handler.setLevel(logging.WARN)
handler.setFormatter(formatter)
app.logger.addHandler(handler)

with app.app_context():
    db.drop_all()
    db.create_all()


@app.route('/users', methods=['POST'])
def users():
    username = request.form.get('name')

    user = User(username)
    print 'User ID: {}'.format(user.id)
    db.session.add(user)
    db.session.commit()

    return jsonify({'id': user.id})

Beispiel #12
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Beispiel #13
0
def initdb():
    db.session.commit()
    db.drop_all()
    db.create_all()
    click.echo('Init Finished!')