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)
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)
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)
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)
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))
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) )