Exemple #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)
Exemple #2
0
    def test_lookup_recipients_for_weekly_mail(self):
        """
        Lookup recipients for weekly mail, make sure unsubscribed users are removed
        """
        restricted_mail = RestrictedMail.objects.create(
            from_address='*****@*****.**', weekly=True)

        users = get_dummy_users(5)
        notAlumni = users[:4]

        unsubscribed_one, unsubscribed_two, no_setting, subscribed, alumni = users
        for user in notAlumni:
            AbakusGroup.objects.get(name="Students").add_user(user)

        NotificationSetting.objects.create(user=unsubscribed_one,
                                           notification_type=WEEKLY_MAIL,
                                           enabled=False)
        NotificationSetting.objects.create(user=unsubscribed_two,
                                           notification_type=WEEKLY_MAIL,
                                           enabled=True,
                                           channels=[PUSH])
        NotificationSetting.objects.create(user=subscribed,
                                           notification_type=WEEKLY_MAIL,
                                           enabled=True,
                                           channels=[EMAIL])
        NotificationSetting.objects.create(user=alumni,
                                           notification_type=WEEKLY_MAIL,
                                           enabled=True,
                                           channels=[EMAIL])

        recipients = restricted_mail.lookup_recipients()

        self.assertListEqual(sorted(recipients),
                             sorted([no_setting.email, subscribed.email]))
Exemple #3
0
    def test_delete_user_registration_before_start_time(self):
        event = Event.objects.get(title="POOLS_NO_REGISTRATIONS")
        event_id = event.id
        users = get_dummy_users(4)

        for user in users:
            AbakusGroup.objects.get(name="Abakus").add_user(user)
            registration = Registration.objects.get_or_create(event=event,
                                                              user=user)[0]
            event.register(registration)

        registration = event.registrations.exclude(pool=None).first()
        user_id = registration.user.id
        no_of_regs_before = event.number_of_registrations
        no_of_waiting_registrations_before = event.waiting_registrations.count(
        )
        self.assertEqual(no_of_waiting_registrations_before, 1)

        User.objects.get(id=user_id).delete(force=True)
        event.refresh_from_db()
        no_of_waiting_registrations_after = event.waiting_registrations.count()

        # Check that users have been bumped
        self.assertEqual(no_of_waiting_registrations_after, 0)
        self.assertEqual(event.number_of_registrations, no_of_regs_before)
        # Verify that the event still exists
        self.assertEqual(len(Event.objects.all().filter(id=event_id)), 1)
        # Verify that user is deleted
        self.assertEqual(len(User.objects.all().filter(id=user_id)), 0)
        # Legacy_registration_count should not be incremented if the event has not started
        self.assertEqual(event.legacy_registration_count, 0)
Exemple #4
0
    def test_isnt_bumped_with_penalties(self):
        """ Users should not be bumped if they have 3 penalties. """
        self.event.start_time = timezone.now() + timedelta(days=1)
        self.event.merge_time = timezone.now() + timedelta(hours=12)
        self.event.save()

        self.pool_one.activation_date = timezone.now() - timedelta(days=1)
        self.pool_one.save()

        self.pool_two.activation_date = timezone.now() + timedelta(minutes=30)
        self.pool_two.save()

        users = get_dummy_users(2)

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

        for user in users:
            AbakusGroup.objects.get(name="Webkom").add_user(user)
            registration = Registration.objects.get_or_create(event=self.event,
                                                              user=user)[0]
            self.event.register(registration)

        bump_waiting_users_to_new_pool()

        self.assertEqual(self.pool_two.registrations.count(), 0)
        self.assertEqual(self.event.waiting_registrations.count(), 1)
Exemple #5
0
 def setUp(self):
     Pool.objects.all().update(activation_date=timezone.now() +
                               timedelta(hours=2),
                               name="Webkom")
     self.recipient = get_dummy_users(1)[0]
     AbakusGroup.objects.get(name="Webkom").add_user(self.recipient)
     self.pool = Pool.objects.first()
     self.notifier = RegistrationReminderNotification(self.recipient,
                                                      event=self.pool.event)
Exemple #6
0
    def test_users_are_bumped_before_pool_activation(self):
        """" Tests that users are bumped right before pool activation """
        users = get_dummy_users(3)

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(registration)

        self.assertEqual(self.pool_two.registrations.count(), 0)
        bump_waiting_users_to_new_pool()
        self.assertEqual(self.pool_two.registrations.count(), 2)
Exemple #7
0
    def test_isnt_bumped_without_permission(self):
        """ Tests that a waiting user isnt bumped to a pool it cant access. """
        users = get_dummy_users(2)

        for user in users:
            AbakusGroup.objects.get(name='Abakus').add_user(user)
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(registration)

        bump_waiting_users_to_new_pool()

        self.assertEqual(self.pool_two.registrations.count(), 0)
        self.assertEqual(self.event.waiting_registrations.count(), 1)
Exemple #8
0
    def test_ensure_pool_counters_raise_error_when_incorrect(self):
        """Test that counter raises error due to incorrect counter"""

        users = get_dummy_users(3)

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            Registration.objects.get_or_create(event=self.event, user=user, pool=self.pool_one)

        self.assertGreater(self.pool_one.registrations.count(), self.pool_one.counter)

        with self.assertRaises(PoolCounterNotEqualToRegistrationCount):
            check_that_pool_counters_match_registration_number()
Exemple #9
0
    def test_retrieve_payment(self, mock_initiate_payment,
                              mock_stripe_retrieve):
        """Test that you can retrieve a payment after registering"""
        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]

        registration.payment_intent_id = "test_id"
        registration.save()
        async_retrieve_payment(registration.id)
        mock_stripe_retrieve.assert_called_once_with(
            registration.payment_intent_id)
Exemple #10
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),
        )
Exemple #11
0
    def test_too_many_users_waiting_for_bump(self):
        """ Tests that only 2 users are bumped to a new pool with capacity = 2. """
        users = get_dummy_users(4)
        registrations = []

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(registration)
            registrations.append(Registration.objects.get(id=registration.id))

        bump_waiting_users_to_new_pool()

        self.assertEqual(self.pool_two.registrations.count(), 2)
        self.assertIsNone(registrations[3].pool)
Exemple #12
0
    def test_pool_counter_check_ignore_merged_events(self):
        """Test that counter raises error due to incorrect counter"""

        self.event.merge_time = timezone.now() - timedelta(days=1)
        self.event.save()
        users = get_dummy_users(3)

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            reg = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(reg)

        self.assertGreater(self.pool_one.registrations.count(), self.pool_one.counter)

        check_that_pool_counters_match_registration_number()
Exemple #13
0
    def test_users_are_bumped_after_pool_activation(self):
        """ Tests that users are bumped right after pool activation. """
        users = get_dummy_users(3)

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(registration)

        self.pool_two.activation_date = timezone.now() - timedelta(minutes=30)
        self.pool_two.save()

        bump_waiting_users_to_new_pool()

        self.assertEqual(self.pool_two.registrations.count(), 2)
Exemple #14
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()
Exemple #15
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)
Exemple #16
0
    def test_isnt_bumped_if_activation_is_far_into_the_future(self):
        """ Users should not be bumped if the pool is activated more than
            35 minutes in the future. """
        self.pool_two.activation_date = timezone.now() + timedelta(minutes=40)
        self.pool_two.save()

        users = get_dummy_users(2)

        for user in users:
            AbakusGroup.objects.get(name='Webkom').add_user(user)
            registration = Registration.objects.get_or_create(event=self.event, user=user)[0]
            self.event.register(registration)

        bump_waiting_users_to_new_pool()

        self.assertEqual(self.pool_two.registrations.count(), 0)
        self.assertEqual(self.event.waiting_registrations.count(), 1)
Exemple #17
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)
Exemple #18
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)
Exemple #19
0
    def test_creator_notification_when_event_is_past_due_date_multiple(self, mock_notification):
        """Test that email is sent when event is past due and multiple users has not paid"""

        self.event.payment_due_date = timezone.now() - timedelta(days=2)
        self.event.save()

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

        registration_two = Registration.objects.get_or_create(event=self.event, user=user)[0]
        self.event.register(registration_two)

        notify_event_creator_when_payment_overdue.delay()
        call = mock_notification.mock_calls[0]
        self.assertEqual(call[1], (self.event.created_by, ))
        self.assertEqual(call[2]['event'], self.event)
        self.assertEqual(2, len(call[2]['users']))
        mock_notification.assert_called_once()
Exemple #20
0
    def test_creator_notification_only_shows_those_who_have_not_paid(self, mock_notification):
        """Test creator notify only list those who has not paid for an overdue event"""

        self.event.payment_due_date = timezone.now() - timedelta(days=2)
        self.event.save()

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

        registration_two = Registration.objects.get_or_create(event=self.event, user=user)[0]
        self.event.register(registration_two)
        registration_two.set_payment_success()

        notify_event_creator_when_payment_overdue.delay()
        call = mock_notification.mock_calls[0]
        self.assertEqual(call[1], (self.event.created_by, ))
        self.assertEqual(call[2]['event'], self.event)
        self.assertEqual(1, len(call[2]['users']))
        mock_notification.assert_called_once()
Exemple #21
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)