def testGetUnread(self): """Test that we can get the user's unread notifications.""" user = User.objects.create_user("test", "*****@*****.**") for i in range(0, 3): notification = UserNotification(recipient=user, contents="Test notification %i" % i) notification.save() notifications = get_unread_notifications(user) self.assertEqual(notifications["alerts"].count(), 0, "There should not be any alert notifications.") unread = notifications["unread"] self.assertEqual(unread.count(), 3, "There should be three unread notifications.") alert = UserNotification(recipient=user, contents="Alert notification", display_alert=True) alert.save() notifications = get_unread_notifications(user) self.assertEqual(notifications["alerts"][0], alert, "Alert notification should have been returned.") unread = notifications["unread"] self.assertEqual(unread.count(), 4, "There should be four unread notifications.")
def supply(request, page_name): """Supply the view_objects content, which are the last 3 unread notifications.""" _ = page_name return get_unread_notifications(request.user, limit=3)