Exemplo n.º 1
0
def test_get_registered_event_persons(dummy_event, dummy_user, dummy_regform):
    create_registration(dummy_regform, {
        'email': '*****@*****.**',
        'first_name': 'John',
        'last_name': 'Doe',
    },
                        notify_user=False)

    user_person = EventPerson.create_from_user(dummy_user, dummy_event)
    no_user_person = EventPerson(email='*****@*****.**',
                                 first_name='John',
                                 last_name='Doe')

    create_registration(dummy_regform, {
        'email': '*****@*****.**',
        'first_name': 'Jane',
        'last_name': 'Doe',
    },
                        notify_user=False)

    no_user_no_reg = EventPerson(email='*****@*****.**',
                                 first_name='No',
                                 last_name='Show')
    dummy_event.persons.append(user_person)
    dummy_event.persons.append(no_user_person)
    dummy_event.persons.append(no_user_no_reg)
    db.session.flush()

    registered_persons = get_registered_event_persons(dummy_event)
    assert registered_persons == {user_person, no_user_person}
Exemplo n.º 2
0
def test_dump_event(db, dummy_user, dummy_event):
    from indico.modules.search.schemas import EventSchema
    schema = EventSchema()
    dummy_event.description = 'A dummy event'
    dummy_event.keywords = ['foo', 'bar']
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person2 = EventPerson(event=dummy_event,
                          first_name='Admin',
                          last_name='Saurus',
                          affiliation='Indico')
    dummy_event.person_links.append(EventPersonLink(person=person))
    dummy_event.person_links.append(EventPersonLink(person=person2))
    db.session.flush()
    category_id = dummy_event.category_id
    assert schema.dump(dummy_event) == {
        'description':
        'A dummy event',
        'keywords': ['foo', 'bar'],
        'location': {
            'address': '',
            'room_name': '',
            'venue_name': ''
        },
        'persons': [{
            'affiliation': None,
            'name': 'Guinea Pig'
        }, {
            'affiliation': 'Indico',
            'name': 'Admin Saurus'
        }],
        'title':
        'dummy#0',
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'end_dt':
        dummy_event.end_dt.isoformat(),
        'event_id':
        0,
        'start_dt':
        dummy_event.start_dt.isoformat(),
        'type':
        'event',
        'event_type':
        'meeting',
        'url':
        '/event/0/',
    }
Exemplo n.º 3
0
def test_access_everyone(dummy_contribution, dummy_user, dummy_event):
    menu_entry = MenuEntry(event=dummy_event,
                           type=MenuEntryType.page,
                           access=MenuEntryAccess.everyone)
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    assert menu_entry.can_access(dummy_user)
    contrib_person_link = ContributionPersonLink(person=person)
    dummy_contribution.person_links.append(contrib_person_link)
    assert menu_entry.can_access(dummy_user)
    contrib_person_link.is_speaker = True
    assert menu_entry.can_access(dummy_user)
Exemplo n.º 4
0
def test_access_participants_not_registered(dummy_contribution, dummy_user,
                                            dummy_event):
    menu_entry = MenuEntry(event=dummy_event,
                           type=MenuEntryType.page,
                           access=MenuEntryAccess.registered_participants)
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    assert not menu_entry.can_access(dummy_user)
    contrib_person_link = ContributionPersonLink(person=person)
    dummy_contribution.person_links.append(contrib_person_link)
    assert not menu_entry.can_access(dummy_user)
    contrib_person_link.is_speaker = True
    assert not menu_entry.can_access(dummy_user)
Exemplo n.º 5
0
def test_unused_event_person(db, dummy_user, dummy_event, create_contribution,
                             create_subcontribution, create_abstract):
    person = EventPerson.create_from_user(dummy_user, event=dummy_event)
    assert not person.has_links

    dummy_event.person_links.append(EventPersonLink(person=person))
    db.session.flush()
    assert person.has_links

    dummy_event.person_links.clear()
    db.session.flush()
    assert not person.has_links

    set_feature_enabled(dummy_event, 'abstracts', True)
    abstract = create_abstract(dummy_event,
                               'Dummy abstract',
                               submitter=dummy_user,
                               person_links=[
                                   AbstractPersonLink(
                                       person=person,
                                       is_speaker=True,
                                       author_type=AuthorType.primary)
                               ])
    assert person.has_links
    abstract.is_deleted = True
    assert not person.has_links

    contrib = create_contribution(
        dummy_event,
        'Dummy contribution',
        person_links=[ContributionPersonLink(person=person, is_speaker=True)])
    assert person.has_links
    contrib.is_deleted = True
    assert not person.has_links
    db.session.delete(contrib)

    contrib = create_contribution(dummy_event,
                                  'Dummy contribution',
                                  person_links=[])
    assert not person.has_links
    create_subcontribution(contrib,
                           'Dummy subcontribution',
                           person_links=[
                               SubContributionPersonLink(person=person,
                                                         is_speaker=True)
                           ])
    assert person.has_links

    contrib.is_deleted = True
    assert not person.has_links

    db.session.delete(contrib)
    assert not person.has_links
Exemplo n.º 6
0
def test_access_speakers_contrib(dummy_contribution, dummy_user, dummy_event):
    set_feature_enabled(dummy_event, 'registration', True)
    menu_entry = MenuEntry(event=dummy_event,
                           type=MenuEntryType.page,
                           access=MenuEntryAccess.speakers)
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    assert not menu_entry.can_access(dummy_user)
    contrib_person_link = ContributionPersonLink(person=person)
    dummy_contribution.person_links.append(contrib_person_link)
    assert not menu_entry.can_access(dummy_user)
    contrib_person_link.is_speaker = True
    assert menu_entry.can_access(dummy_user)
    dummy_contribution.is_deleted = True
    assert not menu_entry.can_access(dummy_user)
Exemplo n.º 7
0
def test_serialize_principal(app, dummy_event, dummy_user):
    from indico.modules.events.persons.schemas import EventPersonSchema
    with app.test_request_context():
        form = MockForm(event=dummy_event)
    dummy_user.phone = '91'
    dummy_user.address = 'My street'
    dummy_user.affiliation = 'Test'
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    persons = EventPersonSchema(
        only=EventPersonSchema.Meta.public_fields).dumps([person], many=True)
    form.person_link_data.process_formdata([persons])
    del form.person_link_data._submitted_data
    result = form.person_link_data._value()
    assert result[0].get('phone') == ''
    assert result[0].get('address') == ''
    assert result[0].get('affiliation') == 'Test'
Exemplo n.º 8
0
def test_access_speakers_subcontrib(dummy_contribution, dummy_user,
                                    dummy_event):
    set_feature_enabled(dummy_event, 'registration', True)
    menu_entry = MenuEntry(event=dummy_event,
                           type=MenuEntryType.page,
                           access=MenuEntryAccess.speakers)
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    assert not menu_entry.can_access(dummy_user)
    subcontrib = SubContribution(contribution=dummy_contribution,
                                 title='sc',
                                 duration=timedelta(minutes=10))
    subcontrib_person_link = SubContributionPersonLink(person=person)
    subcontrib.person_links.append(subcontrib_person_link)
    assert menu_entry.can_access(dummy_user)
    dummy_contribution.is_deleted = True
    assert not menu_entry.can_access(dummy_user)
    dummy_contribution.is_deleted = False
    subcontrib.is_deleted = True
    assert not menu_entry.can_access(dummy_user)
Exemplo n.º 9
0
def test_submitter_permissions(app, db, dummy_event, dummy_user):
    from indico.modules.events.persons.schemas import PersonLinkSchema
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person_link = EventPersonLink(person=person)
    dummy_event.person_links = [person_link]
    dummy_event.update_principal(person_link.person.principal,
                                 add_permissions={'submit'})
    with app.test_request_context():
        form = MockForm(event=dummy_event)
    form.person_link_data.data = dummy_event.person_links
    # Remove all persons
    form.person_link_data.process_formdata(['[]'])
    dummy_event.person_link_data = form.person_link_data.data
    db.session.flush()
    assert person.has_role('submit', dummy_event) is False
    # Serialize a person_link with a submitter role
    input_person = PersonLinkSchema().dump(person_link)
    input_person['roles'] = ['submitter']
    form.person_link_data.process_formdata([json.dumps([input_person])])
    dummy_event.person_link_data = form.person_link_data.data
    db.session.flush()
    assert person.has_role('submit', dummy_event) is True
Exemplo n.º 10
0
def test_dump_contribution(db, dummy_user, dummy_event, dummy_contribution,
                           create_entry, scheduled):
    from .schemas import ContributionRecordSchema

    person = EventPerson.create_from_user(dummy_user, dummy_event)
    dummy_contribution.person_links.append(
        ContributionPersonLink(person=person))
    dummy_contribution.description = 'A dummy <strong>contribution</strong>'

    extra = {}
    if scheduled:
        create_entry(dummy_contribution,
                     utc.localize(datetime(2020, 4, 20, 4, 20)))
        extra = {
            'start_dt': dummy_contribution.start_dt.isoformat(),
            'end_dt': dummy_contribution.end_dt.isoformat(),
        }

    db.session.flush()
    category_id = dummy_contribution.event.category_id
    schema = ContributionRecordSchema(context={'schema': 'test-contribs'})
    assert schema.dump(dummy_contribution) == {
        '$schema':
        'test-contribs',
        '_access': {
            'delete': ['IndicoAdmin'],
            'owner': ['IndicoAdmin'],
            'update': ['IndicoAdmin'],
        },
        '_data': {
            'description': 'A dummy contribution',
            'location': {
                'address': '',
                'room_name': '',
                'venue_name': ''
            },
            'persons': [{
                'name': 'Guinea Pig'
            }],
            'site': 'http://localhost',
            'title': 'Dummy Contribution',
        },
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'contribution_id':
        dummy_contribution.id,
        'duration':
        20,
        'event_id':
        0,
        'type':
        'contribution',
        'url':
        f'http://localhost/event/0/contributions/{dummy_contribution.id}/',
        **extra
    }
Exemplo n.º 11
0
def test_dump_event(db, dummy_user, dummy_event):
    from .schemas import EventRecordSchema

    schema = EventRecordSchema(context={'schema': 'test-events'})
    dummy_event.description = 'A dummy <strong>event</strong>'
    dummy_event.keywords = ['foo', 'bar']
    person = EventPerson.create_from_user(dummy_user, dummy_event)
    person2 = EventPerson(event=dummy_event,
                          first_name='Admin',
                          last_name='Saurus',
                          affiliation='Indico')
    dummy_event.person_links.append(EventPersonLink(person=person))
    dummy_event.person_links.append(EventPersonLink(person=person2))
    db.session.flush()
    category_id = dummy_event.category_id
    assert schema.dump(dummy_event) == {
        '$schema':
        'test-events',
        '_access': {
            'delete': ['IndicoAdmin'],
            'owner': ['IndicoAdmin'],
            'update': ['IndicoAdmin'],
        },
        '_data': {
            'description':
            'A dummy event',
            'keywords': ['foo', 'bar'],
            'location': {
                'address': '',
                'room_name': '',
                'venue_name': ''
            },
            'persons': [{
                'name': 'Guinea Pig'
            }, {
                'affiliation': 'Indico',
                'name': 'Admin Saurus'
            }],
            'site':
            'http://localhost',
            'title':
            'dummy#0'
        },
        'category_id':
        1,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'end_dt':
        dummy_event.end_dt.isoformat(),
        'event_id':
        0,
        'start_dt':
        dummy_event.start_dt.isoformat(),
        'type':
        'event',
        'type_format':
        'meeting',
        'url':
        'http://localhost/event/0/',
    }
Exemplo n.º 12
0
def test_filter_contrib_entries(app, db, dummy_event, create_user,
                                create_contribution, create_registration):
    registered_user = create_user(1)
    registered_speaker = create_user(2)
    unregistered_user = create_user(3)
    dummy_regform = RegistrationForm(event=dummy_event,
                                     title='Registration Form',
                                     currency='USD')
    dummy_event.registrations.append(
        create_registration(registered_user, dummy_regform))
    dummy_event.registrations.append(
        create_registration(registered_speaker, dummy_regform))
    registered_speaker_contribution = create_contribution(
        dummy_event,
        'Registered Speaker',
        person_links=[
            ContributionPersonLink(person=EventPerson.create_from_user(
                registered_speaker, dummy_event),
                                   is_speaker=True)
        ])
    registered_speaker_author_contribution = create_contribution(
        dummy_event,
        'Registered Speaker Author',
        person_links=[
            ContributionPersonLink(person=EventPerson.for_user(
                registered_speaker, dummy_event),
                                   is_speaker=True,
                                   author_type=AuthorType.primary)
        ])
    unregistered_speaker_registered_author_contribution = create_contribution(
        dummy_event,
        'Unregistered Speaker, Registered Author',
        person_links=[
            ContributionPersonLink(person=EventPerson.for_user(
                unregistered_user, dummy_event),
                                   is_speaker=True),
            ContributionPersonLink(person=EventPerson.for_user(
                registered_user, dummy_event),
                                   author_type=AuthorType.primary)
        ])
    registered_speaker_unregistered_author_contribution = create_contribution(
        dummy_event,
        'Registered Speaker, Unregistered Author',
        person_links=[
            ContributionPersonLink(person=EventPerson.for_user(
                registered_user, dummy_event),
                                   is_speaker=True),
            ContributionPersonLink(person=EventPerson.for_user(
                unregistered_user, dummy_event),
                                   author_type=AuthorType.primary)
        ])
    # Filter contributions with registered users
    with app.test_request_context():
        list_gen = ContributionListGenerator(dummy_event)
        list_gen.list_config['filters'] = {'items': {'people': {'registered'}}}
        result = list_gen.get_list_kwargs()
    assert result['contribs'] == [
        registered_speaker_contribution,
        registered_speaker_author_contribution,
        unregistered_speaker_registered_author_contribution,
        registered_speaker_unregistered_author_contribution
    ]

    # Filter contributions with registered speakers
    list_gen.list_config['filters'] = {'items': {'speakers': {'registered'}}}
    with app.test_request_context():
        result = list_gen.get_list_kwargs()
    assert result['contribs'] == [
        registered_speaker_contribution,
        registered_speaker_author_contribution,
        registered_speaker_unregistered_author_contribution
    ]

    # Filter contributions with unregistered speakers and registered users
    list_gen.list_config['filters'] = {
        'items': {
            'speakers': {'not_registered'},
            'people': {'registered'}
        }
    }
    with app.test_request_context():
        result = list_gen.get_list_kwargs()
    assert result['contribs'] == [
        unregistered_speaker_registered_author_contribution
    ]
Exemplo n.º 13
0
def test_dump_contribution(db, dummy_user, dummy_event, dummy_contribution,
                           create_entry, scheduled):
    from indico.modules.search.schemas import ContributionSchema

    person = EventPerson.create_from_user(dummy_user, dummy_event)
    dummy_contribution.person_links.append(
        ContributionPersonLink(person=person))
    dummy_contribution.description = 'A dummy contribution'

    extra = {'start_dt': None, 'end_dt': None}
    if scheduled:
        create_entry(dummy_contribution,
                     utc.localize(datetime(2020, 4, 20, 4, 20)))
        extra = {
            'start_dt': dummy_contribution.start_dt.isoformat(),
            'end_dt': dummy_contribution.end_dt.isoformat(),
        }

    db.session.flush()
    category_id = dummy_contribution.event.category_id
    schema = ContributionSchema()
    assert schema.dump(dummy_contribution) == {
        'description':
        'A dummy contribution',
        'location': {
            'address': '',
            'room_name': '',
            'venue_name': ''
        },
        'persons': [{
            'affiliation': None,
            'name': 'Guinea Pig'
        }],
        'title':
        'Dummy Contribution',
        'category_id':
        category_id,
        'category_path': [
            {
                'id': 0,
                'title': 'Home',
                'url': '/'
            },
            {
                'id': category_id,
                'title': 'dummy',
                'url': f'/category/{category_id}/'
            },
        ],
        'contribution_id':
        dummy_contribution.id,
        'duration':
        20,
        'event_id':
        0,
        'type':
        'contribution',
        'url':
        f'/event/0/contributions/{dummy_contribution.id}/',
        **extra
    }