def test_remove_user_from_group(db_session, awg_users, awg_groups): accesses = (db_session.query(AccessPrivilege).join( AccessPrivilege.user).filter(User.username == "awg_user").all()) projects = [ db_session.query(Project).filter( Project.id == item.project_id).first().name for item in accesses if item.project_id != None ] assert "test_project_1" in projects assert "test_project_2" in projects group_access = (db_session.query(UserToGroup).join( UserToGroup.user).filter(User.username == "awg_user").all()) groups = [ db_session.query(Group).filter(Group.id == group.group_id).first().name for group in group_access ] assert "test_group_1" in groups assert "test_group_2" in groups adm.remove_user_from_groups(db_session, "awg_user", ["test_group_1", "test_group_2"]) accesses = (db_session.query(AccessPrivilege).join( AccessPrivilege.user).filter(User.username == "awg_user").all()) assert accesses == [] group_access = (db_session.query(UserToGroup).join( UserToGroup.user).filter(User.username == "awg_user").all()) assert group_access == []
def remove_user_from_groups(username): """ Create a user to group relationship in the database Returns a json object """ groups = request.get_json().get("groups", []) return jsonify( admin.remove_user_from_groups(current_session, username, groups=groups))
def test_remove_user_from_wrong_group(db_session, awg_users, awg_groups): with pytest.raises(NotFound): adm.remove_user_from_groups(db_session, "awg_user", ["test_group_4"])