Esempio n. 1
0
def test_bump_user_without_event_priorities():
    """Test that users are not swapped when event does not have any priorities."""
    event = EventFactory(limit=1)

    registration_not_on_waiting_list = RegistrationFactory(event=event,
                                                           user=UserFactory())
    registration_on_waiting_list = RegistrationFactory(event=event,
                                                       user=UserFactory())

    assert not registration_not_on_waiting_list.is_on_wait
    assert registration_on_waiting_list.is_on_wait
Esempio n. 2
0
def test_registration_in_queue_is_deleted_if_no_priority_registration_in_waiting_list_first_registration_is_moved_to_queue(
    event_with_registrations_and_priority,
    registration_in_priority_pool,
    priority_user_class,
    non_priority_user_study,
):
    """Swap registration when user is deleted with first registration in waiting list, if no priority exists."""
    user_not_in_priority_pool = UserFactory(
        user_class=priority_user_class.value,
        user_study=non_priority_user_study.value)
    registration_not_in_priority_pool = RegistrationFactory(
        event=event_with_registrations_and_priority,
        user=user_not_in_priority_pool)
    other_user_not_in_priority_pool = UserFactory(
        user_class=priority_user_class.value,
        user_study=non_priority_user_study.value)
    other_registration_not_in_priority_pool = RegistrationFactory(
        event=event_with_registrations_and_priority,
        user=other_user_not_in_priority_pool,
    )

    registration_in_priority_pool.delete()
    registration_not_in_priority_pool.refresh_from_db()
    other_registration_not_in_priority_pool.refresh_from_db()

    assert not registration_in_priority_pool.event.registrations.filter(
        registration_id=registration_in_priority_pool.registration_id).exists(
        )
    assert not registration_not_in_priority_pool.is_on_wait
    assert other_registration_not_in_priority_pool.is_on_wait
Esempio n. 3
0
def test_bump_user_when_user_is_not_in_priority_pool_and_event_is_full(
        event, user_not_in_priority_pool):
    """Test that users are not swapped when new user is not prioritized and event is full."""
    registration_not_in_priority_pool = RegistrationFactory(
        event=event, user=user_not_in_priority_pool)
    other_user_not_in_priority_pool = UserFactory(
        user_class=user_not_in_priority_pool.user_class,
        user_study=user_not_in_priority_pool.user_study,
    )
    other_registration_not_in_priority_pool = RegistrationFactory(
        event=event, user=other_user_not_in_priority_pool)

    assert not registration_not_in_priority_pool.is_on_wait
    assert other_registration_not_in_priority_pool.is_on_wait
Esempio n. 4
0
def test_bump_user_when_event_is_not_full(
    event,
    user_not_in_priority_pool,
    user_in_priority_pool,
):
    """
    Test that a non prioritized user is not swapped with
    a prioritized user if the event is not full.
    """
    event.limit = 10

    registration_not_in_priority_pool = RegistrationFactory(
        event=event, user=user_not_in_priority_pool)
    registration_in_priority_pool = RegistrationFactory(
        event=event, user=user_in_priority_pool)

    assert not registration_in_priority_pool.is_on_wait
    assert not registration_not_in_priority_pool.is_on_wait
Esempio n. 5
0
def test_create_when_event_has_waiting_list(
        event_with_registrations_and_priority):
    """Should put user on waiting list if the event has a waiting list."""
    assert event_with_registrations_and_priority.has_waiting_list()

    new_registration = RegistrationFactory(
        event=event_with_registrations_and_priority, user=UserFactory())

    assert new_registration.is_on_wait
Esempio n. 6
0
def test_swap_users_when_event_is_full(event,
                                       registration_not_in_priority_pool,
                                       user_in_priority_pool):
    """Test that a prioritized user is swapped with a non prioritized user if the event is full."""

    registration_in_priority_pool = RegistrationFactory(
        event=event, user=user_in_priority_pool)

    assert not registration_in_priority_pool.is_on_wait
    assert registration_not_in_priority_pool.is_on_wait
Esempio n. 7
0
def test_users_are_not_swapped_when_both_are_in_a_priority_pool(
    event_with_registrations_and_priority,
    registration_in_priority_pool,
    priority_user_class,
    priority_user_study,
):
    """Should not swap users if both are in a priority pool."""
    user_in_priority_pool = UserFactory(user_class=priority_user_class.value,
                                        user_study=priority_user_study.value)
    other_registration_in_priority_pool = RegistrationFactory(
        event=event_with_registrations_and_priority,
        user=user_in_priority_pool)

    assert not registration_in_priority_pool.is_on_wait
    assert other_registration_in_priority_pool.is_on_wait
Esempio n. 8
0
def test_retrieve_evaluation_event_form_as_member_when_has_not_attended_event(
        member):
    """A member should not be able to retrieve an event evaluation form if they have not attended the event."""
    event = EventFactory(limit=1)
    registration = RegistrationFactory(user=member,
                                       event=event,
                                       is_on_wait=False,
                                       has_attended=False)
    form = EventFormFactory(event=registration.event,
                            type=EventFormType.EVALUATION)

    client = get_api_client(user=member)
    url = _get_form_detail_url(form)
    response = client.get(url)

    assert response.status_code == status.HTTP_403_FORBIDDEN
Esempio n. 9
0
def test_that_bump_user_registers_on_waiting_list_when_no_one_to_swap_with_and_event_is_full(
    event_with_registrations_and_priority,
    user_in_priority_pool,
    registration_in_priority_pool,
):
    """
    Test that a prioritized user is put on waiting list
    if there is no one to swap places with and the event is full.
    """
    other_user_in_priority_pool = UserFactory(
        user_class=user_in_priority_pool.user_class,
        user_study=user_in_priority_pool.user_study,
    )
    other_registration_in_priority_pool = RegistrationFactory(
        event=event_with_registrations_and_priority,
        user=other_user_in_priority_pool)

    assert not registration_in_priority_pool.is_on_wait
    assert other_registration_in_priority_pool.is_on_wait
Esempio n. 10
0
def test_delete_registration_when_no_users_on_wait_are_in_a_priority_pool_bumps_first_registration_on_wait(
):
    """
    Test that the first registration on wait is moved up when
    a registration is deleted and no registered users are prioritized.
    """
    event = EventFactory(limit=1)
    priority = PriorityFactory(user_study=UserStudy.DATAING,
                               user_class=UserClass.FIRST)
    event.registration_priorities.add(priority)

    user_not_in_priority_pool = UserFactory(user_study=UserStudy.DIGFOR.value,
                                            user_class=UserClass.SECOND.value)

    registration_to_delete = RegistrationFactory(event=event)
    registration_on_wait = RegistrationFactory(event=event,
                                               user=user_not_in_priority_pool)

    registration_to_delete.delete()

    registration_on_wait.refresh_from_db()

    assert not registration_on_wait.is_on_wait
Esempio n. 11
0
def registration():
    return RegistrationFactory()
Esempio n. 12
0
def registration_in_priority_pool(event_with_registrations_and_priority,
                                  user_in_priority_pool):
    return RegistrationFactory(event=event_with_registrations_and_priority,
                               user=user_in_priority_pool)
Esempio n. 13
0
def test_create_calls_send_notification_and_email(
        mock_send_notification_and_mail, event):
    """send_notification_and_email should be called once during creation."""
    RegistrationFactory(event=event, user=UserFactory())

    assert mock_send_notification_and_mail.called_once