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
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
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_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_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())
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
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
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_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()
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_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
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
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
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_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
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
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
def test_meeting_participant_detail(app, user): MEDIA_ENABLED = {'media_participant_enabled': True} category = MeetingCategoryFactory(meeting__settings=MEDIA_ENABLED) meeting = category.meeting data = ParticipantFactory.attributes() data['category_id'] = category.id data['diet'] = 'y' 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', required=False, sort=30) CustomFieldFactory(custom_field_type=CustomField.MEDIA, meeting=meeting, field_type='checkbox') CustomFieldFactory(meeting=meeting) CustomFieldFactory(meeting=meeting, label__english='photo') CustomFieldFactory(custom_field_type=CustomField.MEDIA, meeting=meeting, label__english='photo') 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 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') custom_fields = ( meeting.custom_fields .filter_by(custom_field_type=CustomField.PARTICIPANT) .filter(not_(CustomField.field_type == 'image')) .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.PARTICIPANT, 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