Beispiel #1
0
    def test_unapproved_not_sent(self, mock):
        """Make sure unapproved messages are not sent"""
        # Mark all existing notifications as sent
        Notification.objects.update(consumed=True)

        group = self.create_group()
        user1 = self.create_user()
        user1.add_to_group(group.pk, period='daily')

        thread = self.create_thread(group=group)
        message = thread.first_message

        message.status = 'unapproved'
        message.save()

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 0)

        message.status = 'approved'
        message.save()

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 1)
        mock.delay.assert_called_once_with(user1.pk)
Beispiel #2
0
    def test_called(self, mock):
        """Test that the daily notifications list was properly called"""
        # Mark all existing notifications as sent
        Notification.objects.update(consumed=True)

        group = self.create_group()

        sender = self.create_superuser()
        user1 = self.create_user()
        user2 = self.create_user()
        user3 = self.create_user()

        sender.add_to_group(group.pk)
        user1.add_to_group(group.pk, period='daily')
        user2.add_to_group(group.pk, period='daily')
        user3.add_to_group(group.pk, period='immediate')

        self.create_thread(sender=sender, group=group)

        self.assertEqual(mock.delay.call_count, 0)

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 2)

        self.assertIn(call(user1.pk), mock.delay.call_args_list)
        self.assertIn(call(user2.pk), mock.delay.call_args_list)
Beispiel #3
0
    def test_unapproved_not_sent(self, mock):
        """Make sure unapproved messages are not sent"""
        # Mark all existing notifications as sent
        Notification.objects.update(consumed=True)

        group = self.create_group()
        user1 = self.create_user()
        user1.add_to_group(group.pk, period='daily')

        thread = self.create_thread(group=group)
        message = thread.first_message

        message.status = 'unapproved'
        message.save()

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 0)

        message.status = 'approved'
        message.save()

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 1)
        mock.delay.assert_called_once_with(user1.pk)
Beispiel #4
0
    def test_called(self, mock):
        """Test that the daily notifications list was properly called"""
        # Mark all existing notifications as sent
        Notification.objects.update(consumed=True)

        group = self.create_group()

        sender = self.create_superuser()
        user1 = self.create_user()
        user2 = self.create_user()
        user3 = self.create_user()

        sender.add_to_group(group.pk)
        user1.add_to_group(group.pk, period='daily')
        user2.add_to_group(group.pk, period='daily')
        user3.add_to_group(group.pk, period='immediate')

        self.create_thread(sender=sender, group=group)

        self.assertEqual(mock.delay.call_count, 0)

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 2)

        self.assertIn(call(user1.pk), mock.delay.call_args_list)
        self.assertIn(call(user2.pk), mock.delay.call_args_list)
Beispiel #5
0
    def test_called(self, mock):
        """Test that the daily notifications list was properly called"""
        # Clear out all notifications that may be leftover in the database
        Notification.objects.all().delete()
        group = mommy.make('groups.Group')
        user1 = mommy.make('accounts.User')
        user2 = mommy.make('accounts.User')
        user1.add_to_group(group.pk, period='daily')
        u1sub = Subscription.objects.get(user=user1, group=group)
        user2.add_to_group(group.pk, period='daily')
        u2sub = Subscription.objects.get(user=user2, group=group)

        notification1 = mommy.make(Notification,
                                   recipient=user1,
                                   subscription=u1sub,
                                   message=self.message1)
        notification2 = mommy.make(Notification,
                                   recipient=user2,
                                   subscription=u2sub,
                                   message=self.message1)

        self.assertTrue(
            Notification.objects.filter(pk=notification1.pk,
                                        queued_at__isnull=True).exists())
        self.assertTrue(
            Notification.objects.filter(pk=notification2.pk,
                                        queued_at__isnull=True).exists())

        tasks.send_daily_email_notifications()

        self.assertEqual(mock.delay.call_count, 2)

        self.assertEqual([call(user1.pk), call(user2.pk)],
                         mock.delay.call_args_list)

        self.assertFalse(
            Notification.objects.filter(pk=notification1.pk,
                                        queued_at__isnull=True).exists())
        self.assertFalse(
            Notification.objects.filter(pk=notification2.pk,
                                        queued_at__isnull=True).exists())