コード例 #1
0
def test_create(db_query, client, proposition_factory,
                logged_in_user_with_departments):
    user = logged_in_user_with_departments
    data = factory.build(dict, FACTORY_CLASS=proposition_factory)
    data['tags'] = 'Tag1,' + "".join(
        random.choices(string.ascii_lowercase, k=10)).capitalize()
    data['status'] = data['status'].name
    data['area_id'] = user.departments[0].areas[0].id
    data['related_proposition_id'] = 3
    data['relation_type'] = 'modifies'
    data['external_discussion_url'] = 'http://example.com'

    with assert_difference(db_query(Proposition).count, 1, 'proposition'):
        with assert_difference(db_query(Tag).count, 1, 'tag'):
            client.post('/p', data, status=302)

    proposition = db_query(Proposition).order_by(
        Proposition.id.desc()).limit(1).first()
    other_proposition = db_query(Proposition).get(3)
    assert proposition.modifies == other_proposition

    data['relation_type'] = 'replaces'
    client.post('/p', data, status=302)

    proposition = db_query(Proposition).order_by(
        Proposition.id.desc()).limit(1).first()
    assert proposition.replaces == other_proposition
コード例 #2
0
def test_create(db_query, client, proposition_factory,
                logged_in_user_with_departments):
    user = logged_in_user_with_departments
    # XXX: this is stubid... Is there a better way to get a simple dict from factory boy? Do we need a new strategy?
    data = dict(proposition_factory.stub().__dict__)
    data['tags'] = 'Tag1,' + "".join(
        random.choices(string.ascii_lowercase, k=10)).capitalize()

    data['area_id'] = user.departments[0].areas[0].id
    data['related_proposition_id'] = 3
    data['relation_type'] = 'modifies'
    data['external_discussion_url'] = 'http://example.com'

    with assert_difference(db_query(Proposition).count, 1, 'proposition'):
        with assert_difference(db_query(Tag).count, 1, 'tag'):
            client.post('/p', data, status=302)

    proposition = db_query(Proposition).order_by(
        Proposition.id.desc()).limit(1).first()
    other_proposition = db_query(Proposition).get(3)
    assert proposition.modifies == other_proposition

    data['relation_type'] = 'replaces'
    client.post('/p', data, status=302)

    proposition = db_query(Proposition).order_by(
        Proposition.id.desc()).limit(1).first()
    assert proposition.replaces == other_proposition
コード例 #3
0
def test_create_department(client, db_query, department_factory, logged_in_department_admin):
    data = factory.build(dict, FACTORY_CLASS=department_factory)
    res = client.get('/departments/+new')
    form = assert_deform(res)
    fill_form(form, data)

    with assert_difference(db_query(Department).count, 1):
        form.submit(status=302)
コード例 #4
0
def test_create_page(client, db_query, page_factory, logged_in_global_admin):
    data = factory.build(dict, FACTORY_CLASS=page_factory)
    res = client.get('/pages/+new')
    form = assert_deform(res)
    fill_form(form, data, ['name', 'lang', 'title', 'text'])

    with assert_difference(db_query(Page).count, 1):
        form.submit(status=302)
コード例 #5
0
def test_create_proposition_type(client, db_query, proposition_type_factory, logged_in_global_admin):
    data = factory.build(dict, FACTORY_CLASS=proposition_type_factory)
    res = client.get('/proposition_types/+new')
    form = assert_deform(res)
    fill_form(form, data, ['name', 'abbreviation'])

    with assert_difference(db_query(PropositionType).count, 1):
        form.submit(status=302)
コード例 #6
0
def test_create_customizable_text(client, db_query, customizable_text_factory,
                                  logged_in_global_admin):
    data = factory.build(dict, FACTORY_CLASS=customizable_text_factory)
    res = client.get('/customizable_texts/+new')
    form = assert_deform(res)
    fill_form(form, data, ['name', 'lang', 'text'])

    with assert_difference(db_query(CustomizableText).count, 1):
        form.submit(status=302)
コード例 #7
0
def test_create_policy(client, db_query, policy_factory,
                       logged_in_department_admin):
    data = factory.build(dict, FACTORY_CLASS=policy_factory)
    res = client.get('/policies/+new')
    form = assert_deform(res)
    fill_form(form, data, enum_field_names=['majority', 'voting_system'])

    with assert_difference(db_query(Policy).count, 1):
        form.submit(status=302)
コード例 #8
0
def test_submit_token_new_user(db_query, client, user_login_token_factory):
    token = user_login_token_factory()

    with assert_difference(db_query(User).count, 1, 'user'):
        res = client.post("/token/" + token.token,
                          dict(tos_consent='true'),
                          status=302)

    assert "Set-Cookie" in res.headers
    assert res.headers["Set-Cookie"].startswith("session=")
コード例 #9
0
def test_create(db_query, client, logged_in_user):
    data = {
        'proposition_id': 1,
        'relation_type': 'PRO',
        'title': 'test title',
        'abstract': 'test abstract',
        'details': 'test details'
    }

    with assert_difference(db_query(ArgumentRelation).count, 1):
        client.post("/propositions/1/arguments/", data, status=302)
コード例 #10
0
def test_create(db_query, client, logged_in_user, proposition):
    data = {
        'proposition_id': proposition.id,
        'relation_type': ArgumentType.PRO.name,
        'title': 'test title',
        'abstract': 'test abstract',
        'details': 'test details'
    }

    with assert_difference(db_query(ArgumentRelation).count, 1):
        client.post(f"/p/{proposition.id}/a/", data, status=302)
コード例 #11
0
def test_new_draft(db_query, client, proposition_factory, document,
                   logged_in_user):
    logged_in_user.departments.append(document.area.department)
    data = factory.build(dict, FACTORY_CLASS=proposition_factory)
    data['tags'] = 'Tag1,' + "".join(
        random.choices(string.ascii_lowercase, k=10)).capitalize()
    data['editing_remarks'] = 'editing remarks'

    with assert_no_difference(db_query(Proposition).count, 'proposition'):
        with assert_no_difference(db_query(Tag).count, 'tag'):
            resp = client.post(f'/p/+new_draft?document={document.id}',
                               data,
                               status=200)

    data['document_id'] = document.id
    data['section'] = '1.1'

    with assert_difference(db_query(Proposition).count, 1, 'proposition'):
        with assert_difference(db_query(Tag).count, 1, 'tag'):
            with assert_difference(db_query(Changeset).count, 1, 'changeset'):
                client.post('/p/+new_draft', data, status=302)
コード例 #12
0
def test_create_as_global_admin(db_query, client, voting_phase_factory,
                                voting_phase_type, logged_in_global_admin):
    """Global admin user should be able to update a voting phase regardless of department membership"""

    data = factory.build(dict, FACTORY_CLASS=voting_phase_factory)

    res = client.get('/v/+new')
    form = assert_deform(res)

    fill_form(form, data, ['title', 'name', 'secret', 'description'])
    form.set('date', data['target'], index=0)
    form['phase_type_id'] = voting_phase_type.id

    with assert_difference(db_query(VotingPhase).count, 1):
        form.submit(status=302)
コード例 #13
0
def test_create_voting_phase_type(client, db_query, voting_phase_type_factory,
                                  logged_in_global_admin):
    data = factory.build(dict, FACTORY_CLASS=voting_phase_type_factory)
    res = client.get('/voting_phase_types/+new')
    form = assert_deform(res)
    fill_form(form,
              data,
              field_names=[
                  'name', 'abbreviation', 'description',
                  'secret_voting_possible'
              ],
              enum_field_names=['voting_type'])

    with assert_difference(db_query(VotingPhaseType).count, 1):
        form.submit(status=302)
コード例 #14
0
def test_create_somewhere_as_global_admin(db_query, client,
                                          proposition_factory,
                                          proposition_type, department,
                                          logged_in_global_admin):
    """Global admin user should be able to create a proposition regardless of department membership"""
    data = factory.build(dict, FACTORY_CLASS=proposition_factory)
    data['area_id'] = department.areas[0].id
    data['proposition_type_id'] = proposition_type.id

    # Check precondition: admin is not member of the department
    assert department not in logged_in_global_admin.departments

    # Proposition should be created
    with assert_difference(db_query(Proposition).count, 1, 'proposition'):
        client.post('/p', data, status=302)
コード例 #15
0
def test_create_document(client, db_query, document_factory,
                         proposition_type_factory, logged_in_department_admin):
    department = logged_in_department_admin.managed_departments[0]
    area = department.areas[0]
    proposition_type = proposition_type_factory()
    data = factory.build(dict, FACTORY_CLASS=document_factory)
    del data['area']
    data['area_id'] = area.id
    del data['proposition_type']
    data['proposition_type_id'] = proposition_type.id
    res = client.get('/documents/+new')
    form = assert_deform(res)
    fill_form(form, data)

    with assert_difference(db_query(Document).count, 1):
        form.submit(status=302)
コード例 #16
0
def test_create_voting_phase(client, db_query, voting_phase_type,
                             voting_phase_factory, logged_in_department_admin):
    data = factory.build(dict, FACTORY_CLASS=voting_phase_factory)
    department = logged_in_department_admin.managed_departments[0]

    res = client.get('/v/+new')
    form = assert_deform(res)

    fill_form(form, data, ['title', 'name', 'secret', 'description'])
    form.set('date', data['target'], index=0)
    form['department_id'] = department.id
    form['phase_type_id'] = voting_phase_type.id
    form['status'] = VotingStatus.PREPARING.name

    with assert_difference(db_query(VotingPhase).count, 1):
        form.submit(status=302)
コード例 #17
0
def test_create_ballot(client, db_query, db_session, ballot_factory,
                       voting_phase_factory, proposition_type_factory,
                       logged_in_department_admin):
    data = factory.build(dict, FACTORY_CLASS=ballot_factory)
    department = logged_in_department_admin.managed_departments[0]
    voting_phase = voting_phase_factory(department=department)
    proposition_type = proposition_type_factory()
    area = department.areas[0]
    res = client.get('/b/+new')
    form = assert_deform(res)
    fill_form(form,
              data,
              enum_field_names=['voting_type'],
              skip_field_names=['proposition_type', 'area'])
    form['voting_id'] = voting_phase.id
    form['area_id'] = area.id
    form['proposition_type_id'] = proposition_type.id

    with assert_difference(db_query(Ballot).count, 1):
        form.submit(status=302)