Exemplo n.º 1
0
def deploy():
    """Run deployment tasks."""
    from flask_migrate import upgrade
    from app.model import Role, User

    # migrate database to latest revision
    upgrade()

    # create user roles
    Role.insert_roles()

    # create self-follows for all users
    User.add_self_follows()
Exemplo n.º 2
0
def create_app():
    app.app_context().push()
    password = ''
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqldb://root:' + password + '@127.0.0.1/library?charset=utf8mb4'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['WTF_CSRF_ENABLED'] = False
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    app.config['COVER_URL_PATH'] = COVER_URL_PATH
    import random, time
    secret_key = random._urandom(24) + bytes(str(time.clock()),
                                             encoding='utf-8')
    app.config['SECRET_KEY'] = secret_key

    db.init_app(app)
    from app.model import Role, User, Book_basic
    # db.drop_all()

    db.create_all()

    Role.insert_roles()
    User.insert_admin()
    User.insert_default_user()
    User.insert_teacher()

    Book_basic.insert_origin_books()

    bootstrap.init_app(app)
    login_manager.init_app(app)

    from app.main import main as main_blueprint
    from app.auth import auth as auth_blueprint
    app.register_blueprint(main_blueprint)
    app.register_blueprint(auth_blueprint)

    return app
Exemplo n.º 3
0
 def setUp(self):
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
Exemplo n.º 4
0
 def test_roles_and_permissions(self):
     Role.insert_roles()
     u = User(email='*****@*****.**', password='******')
     self.assertTrue(u.can(Permission.WRITE_ARITICLES))
     self.assertFalse(u.can(Permission.MODERATE_COMMENTS))