def test_moderate_messages(self):
        Message.objects.update(status='pending')

        # Confirm the update has been applied
        self.assertFalse(Message.objects.filter(
            pk=self.message1.pk, status='spam').exists())
        self.assertFalse(Message.objects.filter(
            pk=self.message2.pk, status='approved').exists())
        self.assertFalse(Message.objects.filter(
            pk=self.message3.pk, status='vetoed').exists())

        changes = {
            'spam': [self.message1.pk],
            'approved': [self.message2.pk],
            'vetoed': [self.message3.pk]
        }
        user = self.create_user()
        self.add_perm(user, 'can_moderate_all_messages', 'accounts', 'user')
        total = moderate_messages(changes, user)

        # Intercepting the logger is by far the easiest way to confirm which
        # fields were actually processed
        self.assertEqual(
            MessageModerationAction.objects.filter(
                message__in=[self.message1, self.message2, self.message3]
            ).count(),
            3
        )

        # Confirm correct results
        self.assertTrue(Message.objects.filter(
            pk=self.message1.pk, status='spam').exists())
        self.assertTrue(Message.objects.filter(
            pk=self.message2.pk, status='approved').exists())
        self.assertTrue(Message.objects.filter(
            pk=self.message3.pk, status='vetoed').exists())

        # Confirm the number is correct
        self.assertEqual(total, 3)
Test that messages can be moderated
dataset/ETHPy150Open ofa/connect/open_connect/moderation/tests/test_utils.py/TestModerationAction.test_moderate_messages