Esempio n. 1
0
    def test_create_group_notification(self, mock):
        """Test create_group_notifications."""
        immediate_user = mommy.make('accounts.User')
        immediate_user.add_to_group(self.group.pk)

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that the notification that was created was for user2
        notification = Notification.objects.get(recipient=immediate_user,
                                                message=self.message)

        # Confirm that a new notification was created
        mock.delay.assert_called_once_with(notification.pk)
Esempio n. 2
0
    def test_create_group_notification(self, mock):
        """Test create_group_notifications."""
        immediate_user = mommy.make('accounts.User')
        immediate_user.add_to_group(self.group.pk)

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that the notification that was created was for user2
        notification = Notification.objects.get(
            recipient=immediate_user, message=self.message)

        # Confirm that a new notification was created
        mock.delay.assert_called_once_with(notification.pk)
Esempio n. 3
0
    def test_no_notification_created_for_none_period(self, mock):
        """If a user's period is none, no notification should be created."""
        none_user = mommy.make('accounts.User')
        none_user.add_to_group(self.group.pk, period='none')

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that no notification was created for user3
        self.assertFalse(
            Notification.objects.filter(recipient=none_user,
                                        message=self.message).exists())

        # Confirm that send_immediate_notification was not called
        self.assertFalse(mock.delay.called)
Esempio n. 4
0
    def test_no_notification_created_for_none_period(self, mock):
        """If a user's period is none, no notification should be created."""
        none_user = mommy.make('accounts.User')
        none_user.add_to_group(self.group.pk, period='none')

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that no notification was created for user3
        self.assertFalse(
            Notification.objects.filter(
                recipient=none_user, message=self.message).exists()
        )

        # Confirm that send_immediate_notification was not called
        self.assertFalse(mock.delay.called)
Esempio n. 5
0
    def test_unsubscribed_user_not_added(self):
        """
        Test that a user flagged as 'unsubscribed' does not receive messages
        """
        user = mommy.make('accounts.User', unsubscribed=True)
        user.add_to_group(self.group.pk, period='immediate')
        user.save()

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that no notifications were created
        self.assertFalse(
            Notification.objects.filter(message_id=self.message.pk).exists())

        # Confirm that the unsubscribed user did not get a notification
        self.assertFalse(
            Notification.objects.filter(message_id=self.message.pk,
                                        recipient=user))
Esempio n. 6
0
    def test_unsubscribed_user_not_added(self):
        """
        Test that a user flagged as 'unsubscribed' does not receive messages
        """
        user = mommy.make('accounts.User', unsubscribed=True)
        user.add_to_group(self.group.pk, period='immediate')
        user.save()

        # Execute the group notification
        tasks.create_group_notifications(self.message.pk)

        # Confirm that no notifications were created
        self.assertFalse(
            Notification.objects.filter(message_id=self.message.pk).exists())

        # Confirm that the unsubscribed user did not get a notification
        self.assertFalse(
            Notification.objects.filter(
                message_id=self.message.pk, recipient=user)
        )