Ejemplo 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()
     db.session.commit()
Ejemplo n.º 2
0
 def test_updates_from_form(self):
     test_role = Role(name='TEST_ROLE', permissions=0x111, default=False)
     db.session.add(test_role)
     db.session.commit()
     test_role.update_from_form_data({
         'name': 'NEW_NAME',
         'permissions': 0x222
     })
     self.assertEqual(test_role.name, 'NEW_NAME')
     self.assertEqual(test_role.permissions, 0x222)
Ejemplo n.º 3
0
def db_data_init():
    """
    添加初始化数据命令;
    注意,此命令需要在创建库成功以后。所以先要执行下列操作:
    python manage.py db init
    python manage.py db migrate -m "create tables"
    python manage.py db upgrade
    :return:
    """
    Role.insert_init_role()
    Admin.insert_init_admin()
Ejemplo n.º 4
0
def create_superuser_role():
    try:
        superuser = User.objects.get(email='*****@*****.**')
        role = Role(name='superuser', description='admin of all admins')
        role.save()
        superuser.update(push__roles=role)
    except DoesNotExist:
        print(
            "superuser account must exist in order to create a super admin role"
        )
    except NotUniqueError:
        print("a superuser role already exist")
Ejemplo n.º 5
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")
        oplog = Oplog(admin_id=session["admin_id"],
                      ip=request.remote_addr,
                      reason="添加新角色:%s" % data["name"])
        db.session.add(oplog)
        db.session.commit()
        return redirect(url_for("admin.role_add"))
    return render_template("role_add.html", form=form)
Ejemplo n.º 6
0
 def setUp(self):
     super(BaseAuthedViewTestCase, self).setUp()
     Role.insert_roles()