Exemple #1
0
def test_groups(engine, session):
    _create_all(session)

    alice = User.get_by_username(session, "alice")
    alice.groups.append(Group.get_by_name(session, "users"))
    alice.groups.append(Group.get_by_name(session, "admins"))
    session.commit()

    alice = User.get_by_username(session, "alice")
    assert ["admins", "users"] == sorted(group.name for group in alice.groups)
Exemple #2
0
def test_user_permissions(engine, session):
    _create_all(session)

    alice = User.get_by_username(session, "alice")
    alice.user_permissions.append(Permission.get_by_name(session, "READ"))
    alice.user_permissions.append(Permission.get_by_name(session, "WRITE"))
    session.commit()

    alice = User.get_by_username(session, "alice")
    assert ["READ",
            "WRITE"] == sorted(permission.name
                               for permission in alice.user_permissions)
Exemple #3
0
def test_permissions(engine, session):
    _create_all(session)

    alice = User.get_by_username(session, "alice")

    admins = Group.get_by_name(session, "admins")
    admins.users.append(alice)

    write_permission = Permission.get_by_name(session, "WRITE")
    write_permission.groups.append(admins)

    alice.user_permissions.append(Permission.get_by_name(session, "READ"))
    session.commit()

    alice = User.get_by_username(session, "alice")
    assert ["READ", "WRITE"] == sorted(permission.name
                                       for permission in alice.permissions)
Exemple #4
0
def test_user_case(engine, session):
    _create_all(session)

    user = User(username="******")
    session.add(user)
    session.commit()

    assert User.get_by_username(session, "BOB") is user
    assert user.identity == str(user.id)