示例#1
0
    def test_notification_not_created_for_unsubscribed_user(self):
        """Test that an unsubscribed user won't receive a notification"""
        user = mommy.make('accounts.User', unsubscribed=True)
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        self.assertFalse(
            Notification.objects.filter(recipient=user,
                                        message=self.message).exists())
示例#2
0
    def test_sends_immediate_notification(self, mock_send):
        """User's with a default of immediate notifications should get one."""
        user = mommy.make('accounts.User',
                          direct_notification_period='immediate')
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        notification = Notification.objects.get(recipient=user,
                                                message=self.message)
        mock_send.delay.assert_called_once_with(notification.pk)
示例#3
0
    def test_sends_immediate_notification(self, mock_send):
        """User's with a default of immediate notifications should get one."""
        user = mommy.make(
            'accounts.User', direct_notification_period='immediate')
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        notification = Notification.objects.get(
            recipient=user, message=self.message)
        mock_send.delay.assert_called_once_with(notification.pk)
示例#4
0
    def test_notification_created_for_recipient(self):
        """Test create_recipient_notifications."""
        user = mommy.make('accounts.User')
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        self.assertTrue(
            Notification.objects.filter(recipient=user,
                                        message_id=self.message.pk,
                                        consumed=True,
                                        message=self.message).exists())
示例#5
0
    def test_notification_not_created_for_unsubscribed_user(self):
        """Test that an unsubscribed user won't receive a notification"""
        user = mommy.make('accounts.User', unsubscribed=True)
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        self.assertFalse(
            Notification.objects.filter(
                recipient=user,
                message=self.message
            ).exists()
        )
示例#6
0
    def test_notification_created_for_recipient(self):
        """Test create_recipient_notifications."""
        user = mommy.make('accounts.User')
        mommy.make('connectmessages.UserThread', thread=self.thread, user=user)

        tasks.create_recipient_notifications(self.message.pk)

        self.assertTrue(
            Notification.objects.filter(
                recipient=user,
                message_id=self.message.pk,
                consumed=True,
                message=self.message
            ).exists()
        )
示例#7
0
    def test_sends_immediate_notification(self, mock_send):
        """User's with a default of immediate notifications should get one."""
        delayed_user = self.create_user(direct_notification_period='daily')
        delayed_thread = self.create_thread(recipient=delayed_user,
                                            direct=True)

        tasks.create_recipient_notifications(delayed_thread.first_message.pk)

        self.assertFalse(mock_send.called)

        immediate_user = self.create_user(
            direct_notification_period='immediate')
        immediate_thread = self.create_thread(recipient=immediate_user,
                                              direct=True)

        tasks.create_recipient_notifications(immediate_thread.first_message.pk)

        notification = Notification.objects.get(
            recipient=immediate_user, message=immediate_thread.first_message)
        mock_send.delay.assert_called_once_with(notification.pk)