コード例 #1
0
def test_meeting_participants_export_excel(app, user):
    cat = MeetingCategoryFactory()
    participants = ParticipantFactory.stub_batch(10, meeting=cat.meeting,
                                                 category=cat)
    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(cat.meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        for participant in participants:
            data = vars(participant)
            data['category_id'] = cat.id
            populate_participant_form(cat.meeting, data)
            resp = client.post(url_for('meetings.participant_edit',
                                       meeting_id=cat.meeting.id), data=data)
            assert resp.status_code == 302

        resp = client.get(url_for('meetings.participants_export',
                                  meeting_id=cat.meeting.id))
        assert resp.status_code == 200
        excel_filename = app.config['MEDIA_FOLDER'] / 'participants.xls'
        with open(excel_filename, 'wb') as excel_file:
            excel_file.write(resp.data)
        workbook = xlrd.open_workbook(excel_filename)
        for sheet_name in workbook.sheet_names():
            worksheet = workbook.sheet_by_name(sheet_name)
            assert worksheet.nrows == 11
def test_meeting_custom_field_with_rule_non_deletable(app, user):
    meeting = MeetingFactory()
    rule_field = CustomFieldFactory(meeting=meeting, slug='checkbox',
                                    field_type=CustomField.CHECKBOX)
    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        field = meeting.custom_fields.filter_by(is_primary=True).first()
        cond_val = ConditionValueFactory(condition__rule__meeting=meeting,
                                         condition__field=rule_field,
                                         value='True')
        ActionFactory(rule=cond_val.condition.rule,
                      field=field,
                      is_required=True)

        resp = client.delete(url_for('meetings.custom_field_edit',
                             meeting_id=meeting.id,
                             custom_field_id=rule_field.id))
        assert resp.status_code == 200
        resp_data = json.loads(resp.data)
        assert resp_data['status'] == 'error'
        assert CustomField.query.get(field.id) is not None
コード例 #3
0
def test_meeting_participant_document_delete(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting
    doc_field = DocumentFieldFactory(meeting=meeting)

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data[doc_field.slug] = (StringIO('Test'), 'test.pdf')
    upload_dir = local(app.config['UPLOADED_CUSTOM_DEST'])

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        participant = Participant.query.get(1)
        doc_field_value = (participant.custom_field_values
                           .filter_by(custom_field=doc_field).first())
        assert doc_field_value is not None
        assert upload_dir.join(doc_field_value.value).check()

        resp = client.delete(url_for('meetings.custom_field_upload',
                                     participant_id=participant.id,
                                     field_slug=doc_field.slug))
        assert resp.status_code == 200
        assert not upload_dir.join(doc_field_value.value).check()
        assert participant.custom_field_values.count() == 0
コード例 #4
0
def test_meeting_participant_detail_custom_fields_grouping(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['diet'] = 'y'
    data['lunch'] = 'y'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        CustomFieldFactory(meeting=meeting, field_type='checkbox',
                           label__english='diet', required=False, sort=30)
        CustomFieldFactory(meeting=meeting)
        CustomFieldFactory(field_type='event', meeting=category.meeting,
                           required=False, label__english='Lunch')
        CustomFieldFactory(field_type='event', meeting=category.meeting,
                           required=False, label__english='Dinner')
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)
        assert resp.status_code == 302

        resp = client.get(url_for('meetings.participant_detail',
                                  meeting_id=category.meeting.id,
                                  participant_id=1))

        assert resp.status_code == 200
        html = PyQuery(resp.data)
        assert len(html('#Events')) == 1
        assert len(html('#Flags tr')) == 4
def test_meeting_media_participant_list(app, user):
    category = MeetingCategoryFactory(meeting__settings=MEDIA_ENABLED,
                                      category_type=Category.MEDIA)
    MediaParticipantFactory.create_batch(7, category=category)
    ParticipantFactory.create_batch(5, meeting=category.meeting)
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting,
                                      form_class=MediaParticipantDummyForm)
        with app.client.session_transaction() as sess:
            sess['user_id'] = user.id
        data = {
            'columns[0][data]': 'id',
            'columns[1][data]': 'last_name',
            'columns[2][data]': 'category_id',
            'order[0][column]': 0,
            'order[0][dir]': 'asc'
        }
        url = url_for('meetings.media_participants_filter',
                      meeting_id=category.meeting.id)
        url = url + '?' + urlencode(data)
        resp = app.client.get(url)
        assert resp.status_code == 200
        resp_data = json.loads(resp.data)
        assert resp_data['recordsTotal'] == 7
        for participant in resp_data['data']:
            assert (Participant.query.get(participant['id']).participant_type
                    == Participant.MEDIA)
コード例 #6
0
def test_meeting_participant_detail_document_field(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting
    doc_field = DocumentFieldFactory(meeting=meeting)

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data[doc_field.slug] = (StringIO('Test'), 'test.pdf')

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        participant = Participant.query.get(1)
        doc_field_value = (participant.custom_field_values
                           .filter_by(custom_field=doc_field).first())
        assert doc_field_value is not None
        resp = client.get(url_for('meetings.participant_detail',
                                  meeting_id=meeting.id,
                                  participant_id=participant.id))
        assert resp.status_code == 200
        doc_detail_value = PyQuery(resp.data)('tr#row-' + doc_field.slug)
        assert len(doc_detail_value) == 1
        assert (doc_field_value.value ==
                doc_detail_value[0].find('td').text_content())
コード例 #7
0
def test_meeting_rule_on_registration(app, user, default_meeting):
    category = MeetingCategoryFactory(meeting__online_registration=True)
    meeting = category.meeting

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(meeting)
        fields = meeting.custom_fields
        cond_field = fields.filter_by(slug='category_id').one()
        action_field = fields.filter_by(slug='represented_organization').one()
        cond_value = ConditionValueFactory(condition__rule__meeting=meeting,
                                           condition__field=cond_field,
                                           value=category.id)
        ActionFactory(rule=cond_value.condition.rule, field=action_field,
                      is_required=True)
        assert Rule.query.count() == 1

        data = ParticipantFactory.attributes()
        data['category_id'] = category.id
        resp = register_participant_online(client, data, meeting)
        errors = PyQuery(resp.data)('div.text-danger')
        assert len(errors) == 1
        assert meeting.participants.count() == 0
def test_meeting_custom_field_with_rule_unable_change_type(app, user):
    meeting = MeetingFactory()
    rule_field = CustomFieldFactory(meeting=meeting, slug='checkbox',
                                    field_type=CustomField.CHECKBOX)
    data = CustomFieldFactory.attributes()
    data['label-english'] = data['label'].english
    data['hint-english'] = data['hint'].english
    data['field_type'] = CustomField.TEXT
    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        field = meeting.custom_fields.filter_by(is_primary=True).first()
        cond_val = ConditionValueFactory(condition__rule__meeting=meeting,
                                         condition__field=rule_field,
                                         value='True')
        ActionFactory(rule=cond_val.condition.rule,
                      field=field,
                      is_required=True)

        resp = client.post(url_for('meetings.custom_field_edit',
                           meeting_id=meeting.id,
                           custom_field_id=rule_field.id), data=data)
        assert resp.status_code == 200
        assert len(PyQuery(resp.data)('.text-danger small')) == 1
        assert rule_field.field_type == CustomField.CHECKBOX
コード例 #9
0
def test_meeting_participant_add_success(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        add_custom_fields_for_meeting(meeting,
                                      form_class=MediaParticipantDummyForm)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)

        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        part = Participant.query.current_meeting().participants().first()
        assert part.participant_type.code == Participant.PARTICIPANT
        assert part.category
        assert part.title
        assert part.language
        assert part.first_name
        assert part.last_name
        assert part.email
        assert part.country
        activity_log = ActivityLog.query.filter_by(meeting_id=meeting.id,
                                                   action='add').count()
        assert activity_log == 1
コード例 #10
0
def test_meeting_multicheckbox_field_non_editable(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    data = MultiDict(ParticipantFactory.attributes())
    data['category_id'] = category.id
    field_data = MultiDict(CustomFieldFactory.attributes())
    field_data['label-english'] = field_data['label'].english
    field_data['hint-english'] = field_data['hint'].english
    field_data['field_type'] = CustomField.MULTI_CHECKBOX
    field_data.setlist('custom_field_choices',
                       ['first_choice', 'second_choice', 'third_choice'])

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(meeting)
        add_multicheckbox_field(client, meeting, field_data)
        field = (CustomField.query
                 .filter_by(slug=field_data['label-english'])
                 .one())

        populate_participant_form(meeting, data)
        data.setlist(field.slug, ['first_choice', 'third_choice'])
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        assert CustomFieldValue.query.count() == 2
        assert field.choices.count() == 3

        field_data.add('custom_field_choices', 'fourth_choice')
        add_multicheckbox_field(client, meeting, field_data, field.id,
                                302)
        assert field.choices.count() == 3
コード例 #11
0
def test_meeting_resistration_open(app, default_meeting):
    category = MeetingCategoryFactory(meeting__online_registration=True)

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        resp = client.get(url_for('meetings.registration',
                                  meeting_acronym=category.meeting.acronym))
        assert PyQuery(resp.data)('form').length == 1
コード例 #12
0
def register_participant_online(client, participant_data, meeting, user=None):
    """Helper function that registers a participant to a meeting."""
    if user:
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
    add_custom_fields_for_meeting(meeting)
    populate_participant_form(meeting, participant_data)
    resp = client.post(url_for('meetings.registration',
                       meeting_acronym=meeting.acronym), data=participant_data)
    return resp
コード例 #13
0
def register_media_participant_online(client, participant_data, meeting,
                                      user=None):
    if user:
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
    add_custom_fields_for_meeting(meeting,
                                  form_class=MediaParticipantDummyForm)
    populate_participant_form(meeting, participant_data)
    resp = client.post(url_for('meetings.media_registration',
                       meeting_acronym=meeting.acronym), data=participant_data)
    return resp
コード例 #14
0
def migrate_meeting(meeting):
    migrated_meeting = models.Meeting()
    title = models.Translation(english=meeting.data['info_description_E'],
                               french=meeting.data['info_description_F'],
                               spanish=meeting.data['info_description_S'])
    db.session.add(title)
    db.session.flush()
    migrated_meeting.title = title

    badge_header = models.Translation(
        english=meeting.data['info_badge_header_E'],
        french=meeting.data['info_badge_header_F'],
        spanish=meeting.data['info_badge_header_S'])
    db.session.add(badge_header)
    db.session.flush()
    migrated_meeting.badge_header = badge_header

    migrated_meeting.acronym = meeting.data['info_acronym']

    try:
        meeting_type = models.MeetingType.query.filter_by(
            slug=meeting.data['info_type']).one()
    except NoResultFound:
        meeting_type = models.MeetingType(slug=meeting.data['info_type'],
                                          label=meeting.data['info_type'])
        db.session.add(meeting_type)
        meeting_type.load_default_phrases()
        db.session.flush()
    migrated_meeting.meeting_type = meeting_type

    date_start = datetime.strptime(meeting.data['info_date_start'],
                                   '%Y-%m-%d').date()
    date_end = datetime.strptime(meeting.data['info_date_end'],
                                 '%Y-%m-%d').date()
    migrated_meeting.date_start = date_start
    migrated_meeting.date_end = date_end

    city = models.Translation(english=meeting.data['info_venue_city_E'],
                              french=meeting.data['info_venue_city_F'],
                              spanish=meeting.data['info_venue_city_S'])

    migrated_meeting.venue_address = meeting.data['info_venue_address']
    migrated_meeting.venue_city = city
    migrated_meeting.venue_country = meeting.data['info_venue_country']
    migrated_meeting.online_registration = (
        True if meeting.data['info_online_registration'] == 'allowed'
        else False)

    db.session.add(migrated_meeting)
    add_custom_fields_for_meeting(migrated_meeting)
    db.session.commit()
    return migrated_meeting
コード例 #15
0
def test_meeting_rule_add_success(app, user):
    category = MeetingCategoryFactory()

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(category.meeting)
        data = _create_simple_rule_data(category.meeting)
        resp = client.post(url_for('meetings.rule_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 302
        assert Rule.query.count() == 1
コード例 #16
0
def test_meeting_default_participant_search_multiple_results(app, user,
                                                             default_meeting):
    meeting = MeetingCategoryFactory()
    ParticipantFactory.create_batch(4, participant_type=Participant.DEFAULT,
                                    meeting=default_meeting)
    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(default_meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.get(url_for('meetings.default_participant_search',
                                  meeting_id=meeting.id, search='John'))
        data = json.loads(resp.data)
        assert len(data) == 4
コード例 #17
0
def test_meeting_primary_custom_field_non_deletable(app, user):
    meeting = MeetingFactory()

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        field = meeting.custom_fields.filter_by(is_primary=True).first()
        resp = client.delete(url_for('meetings.custom_field_edit',
                             meeting_id=meeting.id,
                             custom_field_id=field.id))
        assert resp.status_code == 400
        assert CustomField.query.get(field.id) is not None
コード例 #18
0
def test_meeting_rule_add_fail_same_action_field_twice(app, user):
    category = MeetingCategoryFactory()

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(category.meeting)
        data = _create_simple_rule_data(category.meeting)
        data['actions-1-field'] = data['actions-0-field']
        resp = client.post(url_for('meetings.rule_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 200
        assert Rule.query.count() == 0
        error = PyQuery(resp.data)('div.alert-danger')
        assert len(error) == 1
コード例 #19
0
def test_meeting_participant_add_with_multiple_emails_success(app, user):
    category = MeetingCategoryFactory()
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['email'] = '[email protected] , [email protected], [email protected]'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)

        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
def test_meeting_media_participant_add(app, user):
    cat = MeetingCategoryFactory(category_type=Category.MEDIA,
                                 meeting__settings=MEDIA_ENABLED)
    data = MediaParticipantFactory.attributes()
    data['category_id'] = cat.id
    with app.test_request_context():
        add_custom_fields_for_meeting(cat.meeting,
                                      form_class=MediaParticipantDummyForm)
        with app.client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = app.client.post(url_for('meetings.media_participant_edit',
                                       meeting_id=cat.meeting.id), data=data)
        assert resp.status_code == 302
        media_participants = (Participant.query
                              .filter_by(meeting=cat.meeting,
                                         participant_type=Participant.MEDIA))
        assert media_participants.count() == 1
def test_meeting_media_participant_edit(app, user):
    med_part = MediaParticipantFactory(category__meeting__settings=MEDIA_ENABLED,
                                       category__category_type=Category.MEDIA)
    data = MediaParticipantFactory.attributes()
    data['category_id'] = med_part.category.id
    data['first_name'] = name = 'James'
    with app.test_request_context():
        add_custom_fields_for_meeting(med_part.meeting,
                                      form_class=MediaParticipantDummyForm)
        with app.client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = app.client.post(url_for('meetings.media_participant_edit',
                                       meeting_id=med_part.meeting.id,
                                       participant_id=med_part.id),
                               data=data)
        assert resp.status_code == 302
        assert med_part.first_name == name
コード例 #22
0
def test_meeting_participant_add_fail(app, user):
    category = MeetingCategoryFactory()
    CustomFieldFactory(field_type='checkbox', meeting=category.meeting,
                       required=True, label__english='passport')

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 200
        assert not Participant.query.current_meeting().participants().first()
コード例 #23
0
    def _add_primary_custom_fields_for_default_meeting(self):
        from mrt.forms.meetings import DefaultParticipantDummyForm
        from mrt.forms.meetings import DefaultMediaParticipantDummyForm
        from mrt.forms.meetings import add_custom_fields_for_meeting
        form_class = {
            Participant.PARTICIPANT: DefaultParticipantDummyForm,
            Participant.MEDIA: DefaultMediaParticipantDummyForm,
        }.get(self.participant_type.code, DefaultParticipantDummyForm)

        nr_fields = len(list(form_class()))
        count = (
            CustomField.query.filter_by(meeting=self.default_meeting)
            .filter_by(is_primary=True)
        ).count()
        if not nr_fields == count:
            add_custom_fields_for_meeting(
                self.default_meeting,
                form_class=form_class)
コード例 #24
0
def test_meeting_primary_custom_field_type_not_editable(app, user):
    meeting = MeetingFactory()
    data = CustomFieldFactory.attributes()
    data['label-english'] = data.pop('label')
    data['hint-english'] = data.pop('hint')

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        field = meeting.custom_fields.filter_by(is_primary=True).first()
        assert field.field_type.code != data['field_type']
        resp = client.post(url_for('meetings.custom_field_edit',
                                   meeting_id=meeting.id,
                                   custom_field_id=field.id), data=data)
        assert resp.status_code == 302
        assert field.field_type.code != data['field_type']
def test_meeting_media_participant_delete(app, user):
    med_part = MediaParticipantFactory(category__meeting__settings=MEDIA_ENABLED,
                                       category__category_type=Category.MEDIA)

    with app.test_request_context():
        add_custom_fields_for_meeting(med_part.meeting,
                                      form_class=MediaParticipantDummyForm)
        with app.client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = app.client.delete(url_for('meetings.media_participant_edit',
                                         meeting_id=med_part.meeting.id,
                                         participant_id=med_part.id))
        assert resp.status_code == 200
        media_participants = (Participant.query
                              .filter_by(meeting=med_part.meeting,
                                         participant_type=Participant.MEDIA)
                              .active())
        assert media_participants.count() == 0
コード例 #26
0
def test_meeting_rule_add_fail_action_field_is_cond_field(app, user):
    category = MeetingCategoryFactory()

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(category.meeting)
        data = _create_simple_rule_data(category.meeting)
        data['conditions-0-field'] = data['actions-0-field']
        url = url_for('meetings.rule_edit',
                      meeting_id=category.meeting.id,
                      rule_type='participant')
        resp = client.post(url, data=data)
        assert resp.status_code == 200
        assert Rule.query.count() == 0
        error = PyQuery(resp.data)('div.alert-danger')
        assert len(error) == 1
コード例 #27
0
    def _add_primary_custom_fields_for_default_meeting(self):
        from mrt.forms.meetings import DefaultParticipantDummyForm
        from mrt.forms.meetings import DefaultMediaParticipantDummyForm
        from mrt.forms.meetings import add_custom_fields_for_meeting
        form_class = {
            Participant.PARTICIPANT: DefaultParticipantDummyForm,
            Participant.MEDIA: DefaultMediaParticipantDummyForm,
        }.get(self.participant_type.code, DefaultParticipantDummyForm)

        nr_fields = len(list(form_class()))
        count = (
            CustomField.query.filter_by(meeting=self.default_meeting)
            .filter_by(is_primary=True)
        ).count()
        if not nr_fields == count:
            add_custom_fields_for_meeting(
                self.default_meeting,
                form_class=form_class)
コード例 #28
0
def test_meeting_participant_add_fail(app, user):
    category = MeetingCategoryFactory()
    CustomFieldFactory(field_type='checkbox', meeting=category.meeting,
                       required=True, label__english='passport')

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 200
        assert not Participant.query.current_meeting().participants().first()
コード例 #29
0
def test_meeting_participant_add_form_field_order(app, user):
    category = MeetingCategoryFactory()
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        add_custom_fields_for_meeting(category.meeting,
                                      form_class=MediaParticipantDummyForm)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        # CHECK ORDER
        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=category.meeting.id), data=data)
        form_fields = PyQuery(resp.data)('.control-label')
        custom_fields = (
            CustomField.query
            .filter_by(meeting=category.meeting, is_primary=True,
                       custom_field_type=CustomField.PARTICIPANT)
            .order_by(CustomField.sort).all())
        for i, custom_field in enumerate(custom_fields):
            assert custom_field.label.english == form_fields[i].text.strip()

        # CHANGE ORDER
        custom_fields[2], custom_fields[3] = custom_fields[3], custom_fields[2]
        new_order = MultiDict([('items[]', x.id) for x in custom_fields])
        resp = client.post(url_for('meetings.custom_field_update_position'),
                           data=new_order)
        assert resp.status_code == 200

        # CHECK ORDER AGAIN
        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=category.meeting.id), data=data)
        form_fields = PyQuery(resp.data)('.control-label')
        custom_fields = (
            CustomField.query
            .filter_by(meeting=category.meeting, is_primary=True,
                       custom_field_type=CustomField.PARTICIPANT)
            .order_by(CustomField.sort))
        for i, custom_field in enumerate(custom_fields):
            assert custom_field.label.english == form_fields[i].text.strip()
コード例 #30
0
def test_meeting_participant_add_form_field_order(app, user):
    category = MeetingCategoryFactory()
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        add_custom_fields_for_meeting(category.meeting,
                                      form_class=MediaParticipantDummyForm)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id

        # CHECK ORDER
        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=category.meeting.id), data=data)
        form_fields = PyQuery(resp.data)('.control-label')
        custom_fields = (
            CustomField.query
            .filter_by(meeting=category.meeting, is_primary=True,
                       custom_field_type=CustomField.PARTICIPANT)
            .order_by(CustomField.sort).all())
        for i, custom_field in enumerate(custom_fields):
            assert custom_field.label.english == form_fields[i].text.strip()

        # CHANGE ORDER
        custom_fields[2], custom_fields[3] = custom_fields[3], custom_fields[2]
        new_order = MultiDict([('items[]', x.id) for x in custom_fields])
        resp = client.post(url_for('meetings.custom_field_update_position'),
                           data=new_order)
        assert resp.status_code == 200

        # CHECK ORDER AGAIN
        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=category.meeting.id), data=data)
        form_fields = PyQuery(resp.data)('.control-label')
        custom_fields = (
            CustomField.query
            .filter_by(meeting=category.meeting, is_primary=True,
                       custom_field_type=CustomField.PARTICIPANT)
            .order_by(CustomField.sort))
        for i, custom_field in enumerate(custom_fields):
            assert custom_field.label.english == form_fields[i].text.strip()
def test_meeting_primary_custom_field_type_not_editable(app, user):
    meeting = MeetingFactory()
    data = CustomFieldFactory.attributes()
    data['label-english'] = data.pop('label')
    data['hint-english'] = data.pop('hint')

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        field = meeting.custom_fields.filter_by(is_primary=True).first()
        assert field.field_type.code != data['field_type']
        resp = client.post(url_for('meetings.custom_field_edit',
                                   meeting_id=meeting.id,
                                   custom_field_id=field.id),
                           data=data)
        assert resp.status_code == 302
        assert field.field_type.code != data['field_type']
def test_meeting_media_partcipant_add_categories(app, user):
    meeting = MeetingFactory(settings='media_participant_enabled')
    MeetingCategoryFactory.create_batch(3, meeting=meeting,
                                        category_type=Category.MEDIA)
    MeetingCategoryFactory.create_batch(2, meeting=meeting)

    with app.test_request_context():
        add_custom_fields_for_meeting(meeting,
                                      form_class=MediaParticipantDummyForm)
        with app.client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = app.client.get(url_for('meetings.media_participant_edit',
                                      meeting_id=meeting.id))
        categories = PyQuery(resp.data)('input[name=category_id]')
        assert len(categories) == 3
        for category in categories:
            cat_id = category.attrib['value']
            assert (Category.query.get(int(cat_id)).category_type ==
                    Category.MEDIA)
コード例 #33
0
def test_meeting_participant_edit_form_populated(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)

        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        part = Participant.query.current_meeting().participants().first()

        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=meeting.id,
                                  participant_id=part.id))

        sel = PyQuery(resp.data)

        form_title = sel('#title > option:selected').val()
        form_first_name = sel('#first_name').val()
        form_last_name = sel('#last_name').val()
        form_email = sel('#email').val()
        form_category_id = sel('#category_id input').val()
        form_country = sel('#country > option:selected').val()
        form_language = sel('#language > option:selected').val()
        form_repr_region = sel('#represented_region > option:selected').val()

        assert part.title.code == form_title
        assert part.first_name == form_first_name
        assert part.last_name == form_last_name
        assert part.email == form_email
        assert part.category_id == int(form_category_id)
        assert part.country.code == form_country
        assert part.language.code == form_language
        assert part.represented_region.code == form_repr_region
コード例 #34
0
def test_meeting_participant_edit_form_populated(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)

        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        part = Participant.query.current_meeting().participants().first()

        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=meeting.id,
                                  participant_id=part.id))

        sel = PyQuery(resp.data)

        form_title = sel('#title > option:selected').val()
        form_first_name = sel('#first_name').val()
        form_last_name = sel('#last_name').val()
        form_email = sel('#email').val()
        form_category_id = sel('#category_id input').val()
        form_country = sel('#country > option:selected').val()
        form_language = sel('#language > option:selected').val()
        form_repr_region = sel('#represented_region > option:selected').val()

        assert part.title.code == form_title
        assert part.first_name == form_first_name
        assert part.last_name == form_last_name
        assert part.email == form_email
        assert part.category_id == int(form_category_id)
        assert part.country.code == form_country
        assert part.language.code == form_language
        assert part.represented_region.code == form_repr_region
コード例 #35
0
def test_meeting_participant_add_with_multiple_emails_bad_format_fails(app,
                                                                       user):
    category = MeetingCategoryFactory()
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['email'] = 'te [email protected] , test2 @email.com, test@em ail.com'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)

        assert resp.status_code == 200
        error = PyQuery(resp.data)('.text-danger small').text()
        assert error == EmailRequired().message
        assert Participant.query.count() == 0
コード例 #36
0
def test_meeting_participant_add_with_multiple_emails_bad_format_fails(app,
                                                                       user):
    category = MeetingCategoryFactory()
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['email'] = 'te [email protected] , test2 @email.com, test@em ail.com'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)

        assert resp.status_code == 200
        error = PyQuery(resp.data)('.text-danger small').text()
        assert error == EmailRequired().message
        assert Participant.query.count() == 0
コード例 #37
0
def test_meeting_default_media_participant_search(app, user, default_meeting):
    meeting = MeetingCategoryFactory()
    ParticipantFactory(participant_type=Participant.DEFAULT,
                       meeting=default_meeting)
    participant = ParticipantFactory(
        participant_type=Participant.DEFAULT_MEDIA,
        meeting=default_meeting)
    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(default_meeting,
                                      form_class=MediaParticipantDummyForm)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.get(url_for('meetings.default_media_participant_search',
                                  meeting_id=meeting.id, search='John'))
        data = json.loads(resp.data)
        assert len(data) == 1
        assert data[0]['email'] == participant.email
        assert data[0]['first_name'] == participant.first_name
        assert data[0]['last_name'] == participant.last_name
        assert data[0]['title'] == participant.title.code
コード例 #38
0
def test_meeting_participant_event_checkbox_add_form(app, user):
    category = MeetingCategoryFactory()
    meeting = category.meeting

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        CustomFieldFactory(meeting=meeting, field_type='checkbox',
                           label__english='diet', required=False, sort=30)
        CustomFieldFactory(meeting=meeting)
        CustomFieldFactory(field_type='event', meeting=category.meeting,
                           required=False, label__english='Lunch')
        CustomFieldFactory(field_type='event', meeting=category.meeting,
                           required=False, label__english='Dinner')
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.get(url_for('meetings.participant_edit',
                                  meeting_id=meeting.id))
        html = PyQuery(resp.data)
        assert len(html('#Events div.form-group')) == 2
        assert len(html('#Flags div.form-group')) == 4
コード例 #39
0
def test_participant_add_working_language(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['language'] = 'Spanish'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        url = url_for('meetings.participant_edit', meeting_id=meeting.id)

        resp = client.get(url)
        options = PyQuery(resp.data)('select#language option')
        assert len(options) == 3

        resp = client.post(url, data=data)
        assert resp.status_code == 200
コード例 #40
0
def test_participant_add_working_language(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['language'] = 'Spanish'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        url = url_for('meetings.participant_edit', meeting_id=meeting.id)

        resp = client.get(url)
        options = PyQuery(resp.data)('select#language option')
        assert len(options) == 3

        resp = client.post(url, data=data)
        assert resp.status_code == 200
コード例 #41
0
def test_meeting_participant_detail_multicheckbox_list(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    data = MultiDict(ParticipantFactory.attributes())
    data['category_id'] = category.id
    field_data = MultiDict(CustomFieldFactory.attributes())
    field_data['label-english'] = field_data['label'].english
    field_data['hint-english'] = field_data['hint'].english
    field_data['field_type'] = CustomField.MULTI_CHECKBOX
    field_data.setlist('custom_field_choices',
                       ['first_choice', 'second_choice', 'third_choice'])

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(meeting)
        add_multicheckbox_field(client, meeting, field_data)
        field = (CustomField.query
                 .filter_by(slug=field_data['label-english'])
                 .one())

        populate_participant_form(meeting, data)
        choices = ['first_choice', 'third_choice']
        data.setlist(field.slug, choices)
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        participant = Participant.query.get(1)
        participant.attended = True
        resp = client.get(url_for('meetings.participant_detail',
                                  meeting_id=category.meeting.id,
                                  participant_id=1))

        assert resp.status_code == 200
        details = PyQuery(resp.data)('tr#row-' + field.slug)
        assert len(details) == 1
        assert ''.join(choices) == details[0].find('td').text_content()
def test_meeting_protected_field_required_and_visible_not_editable(app, user):
    meeting = MeetingFactory()
    data = CustomFieldFactory.attributes()
    data['label-english'] = data.pop('label')
    data['hint-english'] = data.pop('hint')
    data['required'] = False
    data['visible_on_registration_form'] = False

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        field = meeting.custom_fields.filter_by(is_protected=True).first()
        assert field.is_protected is True
        assert field.visible_on_registration_form is True
        resp = client.post(url_for('meetings.custom_field_edit',
                                   meeting_id=meeting.id,
                                   custom_field_id=field.id),
                           data=data)
        assert resp.status_code == 302
        assert field.is_protected is True
        assert field.visible_on_registration_form is True
コード例 #43
0
def test_meeting_participant_detail_event_list(app, user):
    category = MeetingCategoryFactory()
    CustomFieldFactory(field_type='event', meeting=category.meeting,
                       required=False, label__english='Lunch')
    CustomFieldFactory(field_type='event', meeting=category.meeting,
                       required=False, label__english='Dinner')

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['lunch'] = 'y'
    data['dinner'] = 'y'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(category.meeting)
        populate_participant_form(category.meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=category.meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().participants().first()
        assert CustomFieldValue.query.count() == 2
コード例 #44
0
def test_meeting_registration_success_phrases(app, user, default_meeting):
    meeting = add_new_meeting(app, user)
    category = MeetingCategoryFactory(meeting=meeting)
    online_phrase = meeting.phrases.filter_by(
        group=Phrase.ONLINE_REGISTRATION, name=Phrase.PARTICIPANT).scalar()
    online_phrase.description.english = 'Online success message'
    online_phrase.description.french = 'Bonjour monsiuer online'
    email_phrase = meeting.phrases.filter_by(
        group=Phrase.EMAIL_CONFIRMATION,
        name=Phrase.FOR_PARTICIPANTS).scalar()
    email_phrase.description.english = 'Email success message'
    email_phrase.description.french = 'Bonjour monsiuer email'

    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['language'] = 'French'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        populate_participant_form(meeting, data)
        resp = client.post(url_for('meetings.registration',
                                   meeting_acronym=meeting.acronym,
                                   lang='fr'),
                           data=data)
        assert resp.status_code == 200
        success_message = PyQuery(resp.data)('.text-center h4')
        assert success_message.text() == online_phrase.description.french

        data['language'] = 'English'
        resp = client.post(url_for('meetings.registration',
                                   meeting_acronym=meeting.acronym,
                                   lang='en'),
                           data=data)
        assert resp.status_code == 200
        success_message = PyQuery(resp.data)('.text-center h4')
        assert success_message.text() == online_phrase.description.english
コード例 #45
0
def test_meeting_participant_edit_success(app, user):
    category = MeetingCategoryFactory(meeting__owner=user.staff)
    meeting = category.meeting
    participant = ParticipantFactory(meeting=meeting, category=category)
    data = ParticipantFactory.attributes()
    data['category_id'] = category.id
    data['first_name'] = new_first_name = 'Johnny'

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        add_custom_fields_for_meeting(meeting,
                                      form_class=MediaParticipantDummyForm)
        populate_participant_form(meeting, data)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.participant_edit',
                                   meeting_id=meeting.id,
                                   participant_id=participant.id), data=data)
        assert resp.status_code == 302
        assert participant.first_name == new_first_name
        activity_log = ActivityLog.query.filter_by(meeting_id=meeting.id,
                                                   action='edit').count()
        assert activity_log == 1
コード例 #46
0
def test_meeting_registration_is_prepopulated(app, user, default_meeting):
    meeting = add_new_meeting(app, user)
    MeetingCategoryFactory(meeting=meeting)
    user = UserFactory()
    part = ParticipantFactory(user=user, meeting=default_meeting,
                              category=None,
                              participant_type=Participant.DEFAULT)

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        add_custom_fields_for_meeting(default_meeting)
        add_custom_fields_for_meeting(meeting)
        resp = client.get(url_for('meetings.registration',
                                  meeting_acronym=meeting.acronym))
        assert resp.status_code == 200
        html = PyQuery(resp.data)
        assert part.title.value == html('#title option[selected]').val()
        assert part.first_name == html('#first_name').val()
        assert part.last_name == html('#last_name').val()
        assert part.email == html('#email').val()
        assert part.language.value == html('#language option[selected]').val()
        assert part.country.code == html('#country option[selected]').val()
def test_meeting_media_participant_detail_list(app, user):
    category = MeetingCategoryFactory(meeting__settings=MEDIA_ENABLED,
                                      category_type=Category.MEDIA)
    meeting = category.meeting
    data = MediaParticipantFactory.attributes()
    data['category_id'] = category.id

    client = app.test_client()
    with app.test_request_context():
        add_custom_fields_for_meeting(meeting)
        add_custom_fields_for_meeting(meeting,
                                      form_class=MediaParticipantDummyForm)
        CustomFieldFactory(meeting=meeting, field_type='checkbox',
                           label__english='diet')
        CustomFieldFactory(custom_field_type=CustomField.MEDIA,
                           meeting=meeting, field_type='checkbox', sort=30,
                           required=False)
        CustomFieldFactory(meeting=meeting)
        CustomFieldFactory(meeting=meeting, label__english='photo')
        CustomFieldFactory(custom_field_type=CustomField.MEDIA,
                           meeting=meeting, label__english='photo',
                           required=False, sort=31)
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.post(url_for('meetings.media_participant_edit',
                                   meeting_id=meeting.id), data=data)
        assert resp.status_code == 302
        assert Participant.query.current_meeting().media_participants().first()
        participant = Participant.query.get(1)
        resp = client.get(url_for('meetings.media_participant_detail',
                                  meeting_id=meeting.id,
                                  participant_id=1))

        assert resp.status_code == 200
        details = PyQuery(resp.data)('tr')
        custom_fields = (
            meeting.custom_fields
            .filter_by(custom_field_type=CustomField.MEDIA)
            .filter(not_(CustomField.field_type == CustomField.IMAGE))
            .filter(not_(CustomField.field_type == CustomField.CHECKBOX))
            .order_by(CustomField.sort).all())
        for i, custom_field in enumerate(custom_fields):
            detail_label = details[i].find('th').text_content().strip()
            detail_data = details[i].find('td').text_content().strip()
            try:
                participant_data = getattr(participant, custom_field.slug)
            except AttributeError:
                value = int(custom_field.custom_field_values.first().value)
                participant_data = True if value else False
            assert custom_field.label.english == detail_label
            if isinstance(participant_data, types.choice.Choice):
                assert participant_data.value == detail_data
            elif isinstance(participant_data, types.country.Country):
                assert participant_data.name == detail_data
            elif isinstance(participant_data, bool):
                if participant_data:
                    assert details[i].find('td').find('span') is not None
            elif custom_field.slug == 'category_id':
                assert participant.category.title.english == detail_data
            else:
                assert str(participant_data) == detail_data

        image_custom_fields = (
            meeting.custom_fields
            .filter_by(custom_field_type=CustomField.MEDIA,
                       field_type='image')
            .order_by(CustomField.sort).all())
        image_details = PyQuery(resp.data)('.image-widget h4.text-center')
        for i, custom_field in enumerate(image_custom_fields):
            image_label = image_details[i].text_content().strip()
            assert custom_field.label.english == image_label