Exemplo n.º 1
0
    def test_isnt_bumped_when_not_first_in_line(self):
        """ Tests that a user isnt bumped when not first in the waiting list.
            In practice, this should never happen, because the only reason someone
            is in front of you in the list is if the event is full, which is tested above.
        """

        users = get_dummy_users(3)
        for user in users:
            AbakusGroup.objects.get(name="Abakus").add_user(user)

        p1 = Penalty.objects.create(user=users[2],
                                    reason="test",
                                    weight=3,
                                    source_event=self.event)

        for user in users:
            registration = Registration.objects.get_or_create(event=self.event,
                                                              user=user)[0]
            async_register(registration.id)

        make_penalty_expire(p1)
        check_events_for_registrations_with_expired_penalties.delay()

        self.assertIsNone(Registration.objects.get(user=users[1]).pool)
        self.assertIsNone(Registration.objects.get(user=users[2]).pool)
        self.assertEqual(self.event.number_of_registrations, 1)
Exemplo n.º 2
0
    def test_create_payment_intent_when_registering(
            self, mock_chain, mock_initiate_payment,
            mock_save_and_notify_payment):
        """Test that the payment is created when registering and there is space in a pool"""
        user = get_dummy_users(1)[0]
        AbakusGroup.objects.get(name="Abakus").add_user(user)

        registration = Registration.objects.get_or_create(event=self.event,
                                                          user=user)[0]
        async_register(registration.id)
        mock_chain.assert_called_once_with(
            mock_initiate_payment.s(registration.id),
            mock_save_and_notify_payment.s(registration.id),
        )
Exemplo n.º 3
0
    def test_isnt_bumped_with_too_many_penalties(self):
        """ Tests that a user isn't bumped when going from 4 to 3 active penalties """

        user = get_dummy_users(1)[0]
        AbakusGroup.objects.get(name='Abakus').add_user(user)

        p1 = Penalty.objects.create(user=user, reason='test', weight=1, source_event=self.event)
        Penalty.objects.create(user=user, reason='test2', weight=3, source_event=self.event)

        registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
        async_register(registration.id)

        make_penalty_expire(p1)
        check_events_for_registrations_with_expired_penalties.delay()

        self.assertIsNone(Registration.objects.get(id=registration.id).pool)
        self.assertEqual(self.event.number_of_registrations, 0)
Exemplo n.º 4
0
    def test_is_automatically_bumped_after_penalty_expiration(self):
        """ Tests that the user that registered with penalties is bumped
            by the task after penalty expiration"""

        user = get_dummy_users(1)[0]
        AbakusGroup.objects.get(name='Abakus').add_user(user)

        p1 = Penalty.objects.create(user=user, reason='test', weight=3, source_event=self.event)

        registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
        async_register(registration.id)

        make_penalty_expire(p1)
        check_events_for_registrations_with_expired_penalties.delay()

        self.assertIsNotNone(Registration.objects.get(id=registration.id).pool)
        self.assertEqual(self.event.number_of_registrations, 1)
Exemplo n.º 5
0
    def test_initiate_payment_in_waiting_list(self, mock_initiate_payment):
        """
        Test that the payment intent is not created when the registration is added to the waiting
        list.
        """
        user = get_dummy_users(1)[0]
        AbakusGroup.objects.get(name="Abakus").add_user(user)

        Penalty.objects.create(user=user,
                               reason="test",
                               weight=3,
                               source_event=self.event)

        registration = Registration.objects.get_or_create(event=self.event,
                                                          user=user)[0]
        async_register(registration.id)
        mock_initiate_payment.assert_not_called()
Exemplo n.º 6
0
    def test_isnt_bumped_when_full(self):
        """ Tests that a user isnt bumped when the event is full when penalties expire. """

        users = get_dummy_users(2)
        for user in users:
            AbakusGroup.objects.get(name='Abakus').add_user(user)

        p1 = Penalty.objects.create(user=users[1], reason='test', weight=3, source_event=self.event)

        for user in users:
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            async_register(registration.id)

        make_penalty_expire(p1)
        check_events_for_registrations_with_expired_penalties.delay()

        self.assertIsNone(Registration.objects.get(user=users[1]).pool)
        self.assertEqual(self.event.number_of_registrations, 1)
Exemplo n.º 7
0
    def test_async_bump_post_merge(self):
        """ Tests that a waiting user with penalties is bumped to any pool after merge"""
        self.event.merge_time = timezone.now()
        self.event.save()

        users = get_dummy_users(2)
        for user in users:
            AbakusGroup.objects.get(name='Abakus').add_user(user)

        p1 = Penalty.objects.create(user=users[1], reason='test', weight=3, source_event=self.event)

        for user in users:
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            async_register(registration.id)

        make_penalty_expire(p1)
        check_events_for_registrations_with_expired_penalties.delay()

        self.assertIsNotNone(Registration.objects.get(user=users[1]).pool)
        self.assertEqual(self.event.number_of_registrations, 2)