Esempio n. 1
0
    def test_valid_messages(self, mock):
        """Test where the task is called with multiple recent messages"""
        group = mommy.make('groups.Group')
        moderator = self.create_user(moderator_notification_period=1)
        group.owners.add(moderator)

        message1 = self.generate_pending_message(group, self.one_hour_ago)
        message2 = self.generate_pending_message(group, self.one_hour_ago)

        tasks.send_moderation_notification(moderator.pk,
                                           '2014-09-22T22:00:00+00:00')

        call_kwargs = mock.call_args_list[0][1]

        # Confirm the moderator needs to moderate these messages
        self.assertIn(message1, moderator.messages_to_moderate)
        self.assertIn(message2, moderator.messages_to_moderate)

        # Confirm that an email was sent
        mock.assert_called_once()

        self.assertEqual(call_kwargs['email'], moderator.email)
        self.assertEqual(call_kwargs['subject'],
                         'You have 2 new messages to moderate on Connect')
        self.assertIn(reverse('mod_admin'), call_kwargs['text'])
        self.assertIn(reverse('mod_admin'), call_kwargs['html'])
Esempio n. 2
0
    def test_valid_messages_one_old(self, mock):
        """Test where the task has one recent and one old message"""
        group = mommy.make('groups.Group')
        moderator = self.create_user(moderator_notification_period=1)
        group.owners.add(moderator)

        message1 = self.generate_pending_message(group, self.one_hour_ago)
        message2 = self.generate_pending_message(group, self.one_day_ago)

        tasks.send_moderation_notification(
            moderator.pk, '2014-09-22T22:00:00+00:00')

        call_kwargs = mock.call_args_list[0][1]

        # Confirm the moderator needs to moderate these messages
        self.assertIn(message1, moderator.messages_to_moderate)
        self.assertIn(message2, moderator.messages_to_moderate)

        self.assertEqual(call_kwargs['email'], moderator.email)
        self.assertEqual(call_kwargs['subject'],
                         'You have 1 new message to moderate on Connect')
        self.assertIn(
            'You have 2 to moderate total', call_kwargs['html'])
        self.assertIn(reverse('mod_admin'), call_kwargs['text'])
        self.assertIn(reverse('mod_admin'), call_kwargs['html'])
Esempio n. 3
0
    def test_no_valid_messages(self, mock):
        """Test where the task is called for a user with no recent messages"""
        group = mommy.make('groups.Group')
        moderator = self.create_user(moderator_notification_period=1)
        group.owners.add(moderator)

        self.generate_pending_message(group, self.two_hours_ago)

        tasks.send_moderation_notification(moderator.pk,
                                           '2014-09-22T22:00:00+00:00')

        # Confirm that an email was not sent
        self.assertFalse(mock.called)
Esempio n. 4
0
    def test_no_valid_messages(self, mock):
        """Test where the task is called for a user with no recent messages"""
        group = mommy.make('groups.Group')
        moderator = self.create_user(moderator_notification_period=1)
        group.owners.add(moderator)

        self.generate_pending_message(group, self.two_hours_ago)

        tasks.send_moderation_notification(
            moderator.pk, '2014-09-22T22:00:00+00:00')

        # Confirm that an email was not sent
        self.assertFalse(mock.called)
Esempio n. 5
0
    def test_valid_message_flagged(self, mock):
        """Test where the task is called with one recent flagged message"""
        group = mommy.make('groups.Group')
        moderator = self.create_user(moderator_notification_period=1)
        group.owners.add(moderator)

        message = self.generate_pending_message(
            group, self.one_hour_ago, status='flagged')

        tasks.send_moderation_notification(
            moderator.pk, '2014-09-22T22:00:00+00:00')

        call_kwargs = mock.call_args_list[0][1]

        # Confirm the moderator needs to moderate this message
        self.assertIn(message, moderator.messages_to_moderate)
        # Confirm that an email was sent
        self.assertTrue(mock.called)
        self.assertEqual(call_kwargs['email'], moderator.email)
        self.assertEqual(call_kwargs['subject'],
                         'You have 1 new message to moderate on Connect')
        self.assertIn(reverse('mod_admin'), call_kwargs['text'])
        self.assertIn(reverse('mod_admin'), call_kwargs['html'])