예제 #1
0
def test_register_inactive_candidate(client, blank_user, users):
    blank_user.set_board(FELLOW_BOARD, True)

    tests.utils.web_login(client, blank_user)

    maintenance.begin_election()

    users[0].set_board(FELLOW_ACTIVE, False)
    tests.utils.web_dike_register(client, users[0], [POSITION_COVISION])

    election = maintenance.get_election()
    assert set(
        election.positions.filter_by(
            name=POSITION_COVISION).first().candidates.all()) == set()
예제 #2
0
def test_register_candidates_without_free(client, blank_user, users):
    blank_user.set_board(FELLOW_BOARD, True)

    tests.utils.web_login(client, blank_user)

    maintenance.begin_election()

    tests.utils.web_dike_register(
        client, users[0], [POSITION_BOSS, POSITION_VICE, POSITION_FREE])
    tests.utils.web_dike_register(client, users[1],
                                  [POSITION_BOSS, POSITION_VICE])

    election = maintenance.get_election()
    assert set(
        election.positions.filter_by(
            name=POSITION_BOSS).first().candidates.all()) == {users[0]}
예제 #3
0
def test_register_candidates_board_covision_conflict_allowed(
        client, blank_user, users, feature_flags):
    feature_flags.disable(
        FEATURE_DIKE_CANDIDATE_BOARD_COVISION_CONFLICT_FORBIDDEN)
    blank_user.set_board(FELLOW_BOARD, True)

    tests.utils.web_login(client, blank_user)

    maintenance.begin_election()

    tests.utils.web_dike_register(client, users[0], ["boss", "free"])
    tests.utils.web_dike_register(client, users[1],
                                  ["boss", "free", "covision"])

    election = maintenance.get_election()
    assert set(
        election.positions.filter_by(
            name="boss").first().candidates.all()) == {users[0], users[1]}
예제 #4
0
def test_register_candidates_board_covision_conflict_forbidden(
        client, blank_user, users, feature_flags):
    feature_flags.enable(
        FEATURE_DIKE_CANDIDATE_BOARD_COVISION_CONFLICT_FORBIDDEN)
    blank_user.set_board(FELLOW_BOARD, True)

    tests.utils.web_login(client, blank_user)

    maintenance.begin_election()

    tests.utils.web_dike_register(client, users[0],
                                  [POSITION_BOSS, POSITION_FREE])
    tests.utils.web_dike_register(
        client, users[1], [POSITION_BOSS, POSITION_FREE, POSITION_COVISION])

    election = maintenance.get_election()
    assert set(
        election.positions.filter_by(
            name=POSITION_BOSS).first().candidates.all()) == {users[0]}
예제 #5
0
def test_register_candidates(client, blank_user, users):
    blank_user.set_board(FELLOW_BOARD, True)

    tests.utils.web_login(client, blank_user)

    maintenance.begin_election()

    tests.utils.web_dike_register(
        client, users[0], [POSITION_BOSS, POSITION_VICE, POSITION_FREE])
    tests.utils.web_dike_register(
        client, users[1],
        [POSITION_BOSS, POSITION_TREASURE, POSITION_LIBRARY, POSITION_FREE])
    tests.utils.web_dike_register(client, users[2], [POSITION_COVISION])

    election = maintenance.get_election()
    assert set(
        election.positions.filter_by(
            name=POSITION_BOSS).first().candidates.all()) == {
                users[0], users[1]
            }
    assert set(
        election.positions.filter_by(
            name=POSITION_VICE).first().candidates.all()) == {users[0]}
    assert set(
        election.positions.filter_by(
            name=POSITION_TREASURE).first().candidates.all()) == {users[1]}
    assert set(
        election.positions.filter_by(
            name=POSITION_SECRET).first().candidates.all()) == set()
    assert set(
        election.positions.filter_by(
            name=POSITION_LIBRARY).first().candidates.all()) == {users[1]}
    assert set(
        election.positions.filter_by(
            name=POSITION_FREE).first().candidates.all()) == {
                users[0], users[1]
            }
    assert set(
        election.positions.filter_by(
            name=POSITION_COVISION).first().candidates.all()) == {users[2]}
예제 #6
0
def panel():
    election = maintenance.get_election()
    form = PanelForm()
    log.debug('Dike panel opened')
    if election is None:
        if form.validate_on_submit():
            maintenance.begin_election()
            flash(f'Rozpoczęto wybory.')
            return redirect(url_for('dike.panel'))
        return render_template('dike/panel.html', form=form, mode='inactive')

    elif election.check_flag(ELECTION_REGISTER):

        class DynamicPanelForm(PanelForm):
            pass

        electoral = maintenance.get_electoral(election, full=True)
        for position in electoral:
            for candidate in electoral[position]:
                setattr(DynamicPanelForm, f'{position.id}+{candidate.id}',
                        HiddenField(default="n"))

        form = DynamicPanelForm()
        if form.validate_on_submit():
            if form.unregister_candidates.data:
                unregister_candidates(form, election)
                return redirect(url_for('dike.panel'))

            if form.begin_voting_boss.data:
                election.set_stage(STAGE_BOSS)
            elif form.begin_voting_board.data:
                election.set_stage(STAGE_BOARD)
            elif form.begin_voting_covision.data:
                election.set_stage(STAGE_COVISION)
            maintenance.begin_voting(election)
            flash(f'Rozpoczęto głosowanie.')
            return redirect(url_for('dike.panel'))
        return render_template('dike/panel.html',
                               form=form,
                               mode='register',
                               electoral=electoral)

    elif election.check_flag(ELECTION_VOTING):
        if form.validate_on_submit():
            maintenance.end_voting(election)
            flash('Zakończono głosowanie.')
            return redirect(url_for('dike.reckoning'))

        if not verify_voters(election):
            flash('Illegal voter detected')

        log.debug(f"election.voters_boss.all() = {election.voters_boss.all()}")
        log.debug(
            f"election.voters_board.all() = {election.voters_board.all()}")
        log.debug(
            f"election.voters_covision.all() = {election.voters_covision.all()}"
        )
        log.debug(
            f"election.did_vote({current_user}) = {election.did_vote(current_user)}"
        )

        entitled = reckon_entitled_to_vote(election)
        entitled_checksum = compute_fellows_checksum(entitled)

        return render_template('dike/panel.html',
                               form=form,
                               mode='voting',
                               count=election.count_votes(),
                               entitled_checksum=entitled_checksum)

    else:
        return redirect(url_for('dike.reckoning'))