コード例 #1
0
def add_user(db_session, user_name='username', email='email',
             perms=['root', 'alter_users']):
    user = User(user_name=user_name, email=email, status=0)
    user.set_password('password')
    for perm in perms:
        u_perm = UserPermission(perm_name=perm)
        user.user_permissions.append(u_perm)
    db_session.add(user)
    db_session.flush()
    return user
コード例 #2
0
 def test_users_for_perms(self, db_session):
     user = User(user_name='aaa', email='aaa', status=0)
     user.set_password('password')
     aaa_perm = UserPermission(perm_name='aaa')
     bbb_perm = UserPermission(perm_name='bbb')
     bbb2_perm = UserPermission(perm_name='bbb')
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name='bbb', email='bbb', status=0)
     user2.set_password('password')
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name='ccc', email='ccc', status=0)
     user3.set_password('password')
     group = add_group(db_session, )
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = User.users_for_perms(['aaa'], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == 'aaa'
     users = User.users_for_perms(['bbb'], db_session=db_session).all()
     assert len(users) == 2
     assert ['aaa', 'bbb'] == sorted([u.user_name for u in users])
     users = User.users_for_perms(['aaa', 'bbb', 'manage_apps'],
                                  db_session=db_session)
     assert ['aaa', 'bbb', 'ccc'] == sorted([u.user_name for u in users])
コード例 #3
0
 def test_users_for_perms(self, db_session):
     user = User(user_name='aaa', email='aaa', status=0)
     user.set_password('password')
     aaa_perm = UserPermission(perm_name='aaa')
     bbb_perm = UserPermission(perm_name='bbb')
     bbb2_perm = UserPermission(perm_name='bbb')
     user.user_permissions.append(aaa_perm)
     user.user_permissions.append(bbb_perm)
     user2 = User(user_name='bbb', email='bbb', status=0)
     user2.set_password('password')
     user2.user_permissions.append(bbb2_perm)
     user3 = User(user_name='ccc', email='ccc', status=0)
     user3.set_password('password')
     group = add_group(db_session, )
     group.users.append(user3)
     db_session.add(user)
     db_session.add(user2)
     db_session.flush()
     users = User.users_for_perms(['aaa'], db_session=db_session)
     assert len(users.all()) == 1
     assert users[0].user_name == 'aaa'
     users = User.users_for_perms(['bbb'], db_session=db_session).all()
     assert len(users) == 2
     assert ['aaa', 'bbb'] == sorted([u.user_name for u in users])
     users = User.users_for_perms(['aaa', 'bbb', 'manage_apps'],
                                  db_session=db_session)
     assert ['aaa', 'bbb', 'ccc'] == sorted([u.user_name for u in users])