Exemplo n.º 1
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()
     self.client = self.app.test_client(use_cookies=True)
Exemplo n.º 2
0
 def setUp(self):
     print('setUp')
     self.app = create_app('testing')
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
     Role.insert_roles()
     self.client = self.app.test_client()
Exemplo n.º 3
0
def deploy():
    # python manage.py deploy
    """Run deployment tasks."""
    from flask_migrate import upgrade
    from app.modules 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.º 4
0
def role_add():
    form = RoleForm()
    if form.validate_on_submit():
        data = form.data
        role = Role(name=data["name"],
                    auths=",".join(map(lambda v: str(v), data["auths"])))
        db.session.add(role)
        db.session.commit()
        flash("添加角色权限成功", 'ok')
    return render_template("admin/role_add.html", form=form)
Exemplo n.º 5
0
    def setUpClass(cls):
        # start Firefox
        try:
            cls.client = webdriver.Firefox()
        except:
            pass

        # skip these tests if the browser could not be started
        if cls.client:
            # create the application
            cls.app = create_app('testing')
            cls.app_context = cls.app.app_context()
            cls.app_context.push()

            # suppress logging to keep unittest output clean
            import logging
            logger = logging.getLogger('werkzeug')
            logger.setLevel("ERROR")

            # create the database and populate with some fake data
            db.create_all()
            Role.insert_roles()
            User.generate_fake(10)
            Post.generate_fake(10)

            # add an administrator user
            admin_role = Role.query.filter_by(permissions=0xff).first()
            admin = User(email='*****@*****.**',
                         username='******', password='******',
                         role=admin_role, confirmed=True)
            db.session.add(admin)
            db.session.commit()

            # start the Flask server in a thread
            threading.Thread(target=cls.app.run).start()

            # give the server a second to ensure it is up
            time.sleep(1) 
Exemplo n.º 6
0
def role_add():
    form = RoleForm()
    if form.validate_on_submit():
        data = form.data
        # 判断名称是否存在
        role = Role.query.filter_by(name=data['name']).count()
        if role != 0:
            flash('您要添加的角色名称已经存在', 'err')
            return redirect(url_for('admin.role_add'))
        role = Role(
            name=data['name'],
            # 转换为字符串并用,分割
            auths=','.join(map(lambda v: str(v), data['auths'])))
        db.session.add(role)
        db.session.commit()
        flash('添加角色"%s"成功' % role.name, 'ok')
    return render_template("admin/role_add.html", form=form)
Exemplo n.º 7
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.º 8
0
 def test_roles_and_permissions(self):
     Role.insert_roles()
     user = User(email='*****@*****.**', password='******')
     self.assertTrue(user.can(Permission.WRITE_ARTICLES))
     self.assertFalse(user.can(Permission.MODERATE_COMMENTS))