コード例 #1
0
def get_complex_custom_form_speaker(db, user):
    speaker = get_minimal_speaker(db, user)
    CustomForms(
        event=speaker.event,
        form='speaker',
        field_identifier='heardFrom',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=speaker.event,
        form='speaker',
        field_identifier='bestFriend',
        name='Best Friend',
        type='text',
        is_included=True,
        is_required=True,
        is_complex=True,
    )
    CustomForms(
        event=speaker.event,
        form='speaker',
        field_identifier='transFatContent',
        name='Trans Fat Content',
        type='number',
        is_included=True,
        is_required=False,
        is_complex=True,
    )
    db.session.commit()

    return speaker
コード例 #2
0
def get_complex_custom_form_attendee(db, user):
    attendee = get_minimal_attendee(db, user)
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='jobTitle',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='bestFriend',
        name='Best Friend',
        type='text',
        is_included=True,
        is_required=True,
        is_complex=True,
    )
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='transFatContent',
        name='Trans Fat Content',
        type='number',
        is_included=True,
        is_required=False,
        is_complex=True,
    )
    db.session.commit()

    return attendee
コード例 #3
0
def get_simple_custom_form_session(db, user):
    session = get_minimal_session(db, user)
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='track',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='level',
        type='number',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='shortAbstract',
        type='text',
        is_included=True,
        is_required=True,
    )
    db.session.commit()

    return session
コード例 #4
0
def test_assigning_old_form_name(db):
    event = EventFactoryBasic()
    speaker_custom_form = CustomForms(event=event,
                                      field_identifier='speakingExperience',
                                      form='speaker',
                                      type='text')
    attendee_custom_form = CustomForms(event=event,
                                       field_identifier='taxBusinessInfo',
                                       form='attendee',
                                       type='text')
    session_custom_form = CustomForms(event=event,
                                      field_identifier='longAbstract',
                                      form='session',
                                      type='text')
    none_custom_form = CustomForms(
        event=event,
        field_identifier='showNumber',
        name='Show Number',
        form='attendee',
        type='text',
    )
    db.session.commit()

    assert speaker_custom_form.name == 'Speaking Experience'
    assert none_custom_form.name == 'Show Number'

    db.session.execute("update custom_forms set name = 'None'")
    db.session.commit()

    db.session.refresh(speaker_custom_form)
    db.session.refresh(attendee_custom_form)
    db.session.refresh(session_custom_form)
    db.session.refresh(none_custom_form)

    assert speaker_custom_form.name == 'None'
    assert attendee_custom_form.name == 'None'
    assert session_custom_form.name == 'None'
    assert none_custom_form.name == 'None'

    assign_field_names(db.session)

    db.session.refresh(speaker_custom_form)
    db.session.refresh(attendee_custom_form)
    db.session.refresh(session_custom_form)
    db.session.refresh(none_custom_form)

    assert speaker_custom_form.name == 'Speaking Experience'
    assert attendee_custom_form.name == 'Tax Business Info'
    assert session_custom_form.name == 'Long Abstract'
    # cannot restore custom form field name
    assert none_custom_form.name == 'None'
コード例 #5
0
ファイル: events.py プロジェクト: ydpriya/open-event-server
def create_custom_forms_for_attendees(event):
    """
    Create and save the custom forms for the required fields of attendees.
    :param event:
    :return:
    """
    # common values
    form = 'attendee'
    is_required = True
    is_included = True
    is_fixed = True
    event_id = event.id
    form_type = 'text'

    first_name_form = CustomForms(
        form=form,
        is_required=is_required,
        is_included=is_included,
        is_fixed=is_fixed,
        event_id=event_id,
        type=form_type,
        field_identifier='firstname',
    )

    last_name_form = CustomForms(
        form=form,
        is_required=is_required,
        is_included=is_included,
        is_fixed=is_fixed,
        event_id=event_id,
        type=form_type,
        field_identifier='lastname',
    )

    email_form = CustomForms(
        form=form,
        is_required=is_required,
        is_included=is_included,
        is_fixed=is_fixed,
        event_id=event_id,
        type='email',
        field_identifier='email',
    )

    save_to_db(first_name_form, 'First name form saved')
    save_to_db(last_name_form, 'Last name form saved')
    save_to_db(email_form, 'Email form saved')
コード例 #6
0
def test_throw_complex_custom_form_fields(db, client, jwt, user):
    attendee = get_complex_custom_form_attendee(db, user)
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='secondaryEmail',
        name='Secondary Email',
        type='email',
        is_included=True,
        is_required=False,
        is_complex=True,
    )
    db.session.commit()

    data = json.dumps({
        'data': {
            'type': 'attendee',
            'id': str(attendee.id),
            "attributes": {
                "firstname": "Areeb",
                "lastname": "Jamal",
                "job-title": "Software Engineer",
                "complex-field-values": {
                    "bestFriend": "Bester",
                    "secondary-email": "notanemail.com",
                },
            },
        }
    })

    response = client.patch(
        f'/v1/attendees/{attendee.id}',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )

    db.session.refresh(attendee)

    assert response.status_code == 422

    assert json.loads(response.data) == {
        "errors": [{
            "status": 422,
            "source": {
                "errors": {
                    "secondary_email": ["Not a valid email address."]
                }
            },
            "title": "Unprocessable Entity",
            "detail": "Schema Validation Error",
        }],
        "jsonapi": {
            "version": "1.0"
        },
    }
コード例 #7
0
def test_custom_form_name(db):
    event = EventFactoryBasic()
    speaker_custom_form = CustomForms(event=event,
                                      field_identifier='speakingExperience',
                                      form='speaker',
                                      type='text')
    attendee_custom_form = CustomForms(event=event,
                                       field_identifier='taxBusinessInfo',
                                       form='attendee',
                                       type='text')
    session_custom_form = CustomForms(event=event,
                                      field_identifier='longAbstract',
                                      form='session',
                                      type='text')
    db.session.commit()

    assert speaker_custom_form.name == 'Speaking Experience'
    assert attendee_custom_form.name == 'Tax Business Info'
    assert session_custom_form.name == 'Long Abstract'
コード例 #8
0
def test_override_custom_form_name(db):
    event = EventFactoryBasic()
    overridden_custom_form = CustomForms(
        event=event,
        field_identifier='shippingAddress',
        name='Home Address',
        form='attendee',
        type='text',
    )
    custom_custom_form = CustomForms(
        event=event,
        field_identifier='portNumber',
        name='Portable Number',
        form='attendee',
        type='text',
    )
    db.session.commit()

    assert overridden_custom_form.name == 'Shipping Address'
    assert custom_custom_form.name == 'Portable Number'
コード例 #9
0
def test_throw_invalid_complex_custom_form_fields(db, client, jwt, user):
    attendee = get_complex_custom_form_attendee(db, user)
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='genderFile',
        name='Gender File',
        type='file',
        is_included=True,
        is_required=False,
        is_complex=True,
    )
    db.session.commit()

    data = json.dumps({
        'data': {
            'type': 'attendee',
            'id': str(attendee.id),
            "attributes": {
                "firstname": "Areeb",
                "lastname": "Jamal",
                "job-title": "Software Engineer",
                "complex-field-values": {
                    "bestFriend": "Bester",
                    "gender-file": "notanemail.com",
                },
            },
        }
    })

    response = client.patch(
        f'/v1/attendees/{attendee.id}',
        content_type='application/vnd.api+json',
        headers=jwt,
        data=data,
    )

    db.session.refresh(attendee)

    assert response.status_code == 422

    assert json.loads(response.data) == {
        'errors': [{
            'detail': 'Invalid Field Type: file',
            'source': {
                'pointer': '/data/complex-field-values/gender_file'
            },
            'status': 422,
            'title': 'Unprocessable Entity',
        }],
        'jsonapi': {
            'version': '1.0'
        },
    }
コード例 #10
0
def get_complex_custom_form_session(db, user):
    session = get_minimal_session(db, user)
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='track',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='slidesUrl',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='bestFriend',
        name='Best Friend',
        type='text',
        is_included=True,
        is_required=True,
        is_complex=True,
    )
    CustomForms(
        event=session.event,
        form='session',
        field_identifier='transFatContent',
        name='Trans Fat Content',
        type='number',
        is_included=True,
        is_required=False,
        is_complex=True,
    )
    db.session.commit()

    return session
コード例 #11
0
def get_simple_custom_form_attendee(db, user):
    attendee = get_minimal_attendee(db, user)
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='email',
        type='text',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='taxBusinessInfo',
        type='text',
        is_included=True,
        is_required=True,
    )
    db.session.commit()

    return attendee
コード例 #12
0
def get_simple_custom_form_speaker(db, user):
    speaker = get_minimal_speaker(db, user)
    CustomForms(
        event=speaker.event,
        form='speaker',
        field_identifier='mobile',
        type='number',
        is_included=True,
        is_required=True,
    )
    CustomForms(
        event=speaker.event,
        form='speaker',
        field_identifier='speakingExperience',
        type='text',
        is_included=True,
        is_required=True,
    )
    db.session.commit()

    return speaker
コード例 #13
0
def get_complex_custom_form_order(db, user):
    order = OrderSubFactory(amount=234, status='initializing', user=user)
    attendee = AttendeeSubFactory(order=order)

    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='whatUniversity',
        name='what university',
        type='text',
        is_complex=True,
        is_included=True,
        is_required=True,
    )

    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='whatCollege',
        name='what college',
        type='text',
        is_complex=True,
        is_included=True,
        is_required=True,
    )

    CustomForms(
        event=attendee.event,
        form='attendee',
        field_identifier='naamBatao',
        name='naam batao',
        type='text',
        is_complex=True,
        is_included=True,
        is_required=False,
    )

    db.session.commit()

    return str(order.id)
コード例 #14
0
def get_event(db, user=None):
    event = EventFactoryBasic(state='published')
    if user:
        role, _ = get_or_create(Role, name='owner', title_name='Owner')
        UsersEventsRoles(user=user, event=event, role=role)
    CustomForms(
        event=event,
        form='speaker',
        field_identifier='email',
        type='text',
        is_included=True,
        is_required=True,
    )
    db.session.commit()

    return event
コード例 #15
0
def test_edit_custom_form(db):
    event = EventFactoryBasic()
    overridden_custom_form = CustomForms(
        event=event,
        field_identifier='shippingAddress',
        name='Home Address',
        form='attendee',
        type='text',
    )
    db.session.commit()

    assert overridden_custom_form.name == 'Shipping Address'

    overridden_custom_form.name = 'Daddy Address'
    db.session.commit()

    assert overridden_custom_form.name == 'Shipping Address'