Пример #1
0
 def test_roles(self):
     role = Role(name='admin')
     role.save()
     u = UserFactory()
     u.roles.append(role)
     u.save()
     assert role in u.roles
Пример #2
0
 def test_roles(self):
     role = Role(name='admin')
     role.save()
     u = UserFactory()
     u.roles.append(role)
     u.save()
     assert role in u.roles
Пример #3
0
 def test_roles(self):
     """Add a role to a user."""
     role = Role(name='admin')
     role.save()
     user = UserFactory()
     user.roles.append(role)
     user.save()
     assert role in user.roles
Пример #4
0
 def test_roles(self):
     """Add a role to a user."""
     role = Role(name='admin')
     role.save()
     user = UserFactory()
     user.roles.append(role)
     user.save()
     assert role in user.roles
Пример #5
0
def init_func():
    from app.user.models import Role, User
    role = Role(RoleName="管理员")
    db.session.add(role)
    db.session.commit()
    user = User(UserName="******", password="******", RoleID=role.ID)
    db.session.add(user)
    db.session.commit()
    role = Role(RoleName="用户")
    db.session.add(role)
    db.session.commit()
Пример #6
0
def create_default_roles():
    from app.fixtures.roles import fixture
    result = []
    for key, value in fixture.items():
        role = Role.query.filter_by(name=key).first()
        if not role:
            role = Role(name=key)

        for k, v in value.items():
            setattr(role, k, v)

        role.save()
        result.append(role)
    return result
Пример #7
0
 def admin(self, app_init):
     with app_init.app_context():
         user = User(
             email='*****@*****.**',
             password='******',
         )
         user = UserService().create(user, False)
         role = Role(name='admin')
         user.roles.append(role)
         db.session.add(user)
         db.session.commit()
         yield user
Пример #8
0
def create_role(data):
    role = Role(name=data.get("name", ""), )
    get_session().add(role)
    get_session().flush()
    return
Пример #9
0
 def test_roles_and_permissions(self):
     Role.insert_roles()
     u = User(username='******', email='*****@*****.**', password='******')
     self.assertTrue(u.can(Permission.POST))
     self.assertTrue(u.can(Permission.FOLLOW))
     self.assertFalse(u.can(Permission.MODERATE_COMMENTS))