Esempio n. 1
0
    def test_marked_consumed(self, mock):
        """Test to make sure that the notification was marked consumed"""
        user = self.create_user()

        # Create the group and add the user to that group
        group = self.create_group()
        user.add_to_group(group.pk, period='daily')

        thread1 = self.create_thread(group=group)
        message1 = thread1.first_message
        notification1 = user.notification_set.get(message=message1)

        thread2 = self.create_thread(group=group)
        message2 = thread2.first_message
        notification2 = user.notification_set.get(message=message2)

        self.assertFalse(
            Notification.objects.get(pk=notification1.pk).consumed)
        self.assertFalse(
            Notification.objects.get(pk=notification2.pk).consumed)

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        self.assertTrue(Notification.objects.get(pk=notification1.pk).consumed)
        self.assertTrue(Notification.objects.get(pk=notification2.pk).consumed)
Esempio n. 2
0
    def test_marked_consumed(self, mock):
        """Test to make sure that the notification was marked consumed"""
        user = self.create_user()

        # Create the group and add the user to that group
        group = self.create_group()
        user.add_to_group(group.pk, period='daily')

        thread1 = self.create_thread(group=group)
        message1 = thread1.first_message
        notification1 = user.notification_set.get(message=message1)

        thread2 = self.create_thread(group=group)
        message2 = thread2.first_message
        notification2 = user.notification_set.get(message=message2)

        self.assertFalse(
            Notification.objects.get(pk=notification1.pk).consumed)
        self.assertFalse(
            Notification.objects.get(pk=notification2.pk).consumed)

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        self.assertTrue(
            Notification.objects.get(pk=notification1.pk).consumed)
        self.assertTrue(
            Notification.objects.get(pk=notification2.pk).consumed)
Esempio n. 3
0
 def test_no_notifications(self, mock):
     """If there are no notifications, should return None."""
     user = self.create_user()
     # pylint: disable=assignment-from-none
     response = tasks.send_daily_digest_notification(user.pk)
     self.assertIsNone(response)
     self.assertEqual(mock.call_count, 0)
Esempio n. 4
0
 def test_no_notifications(self, mock):
     """If there are no notifications, should return None."""
     user = self.create_user()
     # pylint: disable=assignment-from-none
     response = tasks.send_daily_digest_notification(user.pk)
     self.assertIsNone(response)
     self.assertEqual(mock.call_count, 0)
Esempio n. 5
0
    def test_outgoing_email(self, mock):
        """Test that the digest is properly sent"""
        user = self.create_user()

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

        thread1 = self.create_thread(group=group)
        thread2 = self.create_thread(group=group)

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        args = mock.call_args[1]

        # To
        email = args['email']
        self.assertIn(user.email, email)
        self.assertIn(user.get_full_name(), email)

        # From
        from_email = args['from_email']
        self.assertIn(settings.DEFAULT_FROM_ADDRESS, from_email)
        self.assertEqual(settings.DEFAULT_FROM_EMAIL, from_email)

        # Subject
        subject = args['subject']
        self.assertIn('2 New Messages', subject)
        days_of_week = [
            'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
            'Saturday'
        ]
        self.assertTrue(any([dayname in subject for dayname in days_of_week]))

        # Body (HTML and Plaintext)
        html = args['html']
        plaintext = args['text']
        self.assertIn(thread1.first_message.text, html)
        self.assertIn(thread2.first_message.text, html)
        self.assertIn('Reply', html)
        self.assertIn(thread1.first_message.clean_text, plaintext)
        self.assertIn(thread2.first_message.clean_text, plaintext)
Esempio n. 6
0
    def test_no_pending_messages(self, mock):
        """Test that pending messages are never part of a digest"""
        user = self.create_user()

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

        valid_thread = self.create_thread(group=group)
        pending_thread = self.create_thread(group=group)

        valid_message = valid_thread.first_message

        pending_message = pending_thread.first_message
        pending_message.status = 'pending'
        pending_message.save()

        valid_notification = user.notification_set.get(
            message=valid_message)
        pending_notification = user.notification_set.get(
            message=pending_message)

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        self.assertTrue(
            Notification.objects.get(pk=valid_notification.pk).consumed)
        self.assertFalse(
            Notification.objects.get(pk=pending_notification.pk).consumed)

        args = mock.call_args[1]
        html = args['html']
        self.assertIn(valid_message.text, html)
        self.assertNotIn(pending_message.text, html)

        # Try making the pending notification valid, and test again
        pending_message.status = 'approved'
        pending_message.save()

        tasks.send_daily_digest_notification(user.pk)

        self.assertTrue(
            Notification.objects.get(pk=pending_notification.pk).consumed)
Esempio n. 7
0
    def test_outgoing_email(self, mock):
        """Test that the digest is properly sent"""
        user = self.create_user()

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

        thread1 = self.create_thread(group=group)
        thread2 = self.create_thread(group=group)

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        args = mock.call_args[1]

        # To
        email = args['email']
        self.assertIn(user.email, email)
        self.assertIn(user.get_full_name(), email)

        # From
        from_email = args['from_email']
        self.assertIn(settings.DEFAULT_FROM_ADDRESS, from_email)
        self.assertEqual(settings.DEFAULT_FROM_EMAIL, from_email)

        # Subject
        subject = args['subject']
        self.assertIn('2 New Messages', subject)
        days_of_week = [
            'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
            'Saturday'
        ]
        self.assertTrue(any([dayname in subject for dayname in days_of_week]))

        # Body (HTML and Plaintext)
        html = args['html']
        plaintext = args['text']
        self.assertIn(thread1.first_message.text, html)
        self.assertIn(thread2.first_message.text, html)
        self.assertIn('Reply', html)
        self.assertIn(thread1.first_message.clean_text, plaintext)
        self.assertIn(thread2.first_message.clean_text, plaintext)
Esempio n. 8
0
    def test_includes_unsubscribe_link(self, mock):
        """Ensure that the digest includes an unsubscribe link"""
        user = self.create_user()

        thread = self.create_thread()

        mommy.make(Notification,
                   recipient=user,
                   message=thread.first_message,
                   subscription__period='daily')

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        args = mock.call_args[1]

        self.assertIn('unsubscribe', args['html'].lower())
        self.assertIn(user.unsubscribe_url, args['html'])
        self.assertIn('unsubscribe', args['html'].lower())
        self.assertIn(user.unsubscribe_url, args['html'])
Esempio n. 9
0
    def test_includes_unsubscribe_link(self, mock):
        """Ensure that the digest includes an unsubscribe link"""
        user = self.create_user()

        thread = self.create_thread()

        mommy.make(
            Notification,
            recipient=user,
            message=thread.first_message,
            subscription__period='daily'
        )

        tasks.send_daily_digest_notification(user.pk)
        mock.assert_called_once()

        args = mock.call_args[1]

        self.assertIn('unsubscribe', args['html'].lower())
        self.assertIn(user.unsubscribe_url, args['html'])
        self.assertIn('unsubscribe', args['html'].lower())
        self.assertIn(user.unsubscribe_url, args['html'])