本文整理汇总了Python中apps.widgets.notifications.models.UserNotification.save方法的典型用法代码示例。如果您正苦于以下问题:Python UserNotification.save方法的具体用法?Python UserNotification.save怎么用?Python UserNotification.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.widgets.notifications.models.UserNotification
的用法示例。
在下文中一共展示了UserNotification.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReadNotifications
# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import save [as 别名]
def testReadNotifications(self):
"""Test that notifications can be marked as read without AJAX."""
notification = UserNotification(recipient=self.user, contents="Test notification")
notification.save()
response = self.client.post(reverse("notifications_read", args=(notification.pk,)), {})
self.assertRedirects(response, reverse("home_index"),
msg_prefix="Marking as read should redirect.")
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "Test notification",
msg_prefix="Notification should be read")
# Test with a referring page.
notification = UserNotification(recipient=self.user, contents="Test notification 2")
notification.save()
response = self.client.post(reverse("notifications_read", args=(notification.pk,)), {},
HTTP_REFERER=reverse("help_index"))
self.assertRedirects(response, reverse("help_index"),
msg_prefix="Marking as read should redirect.")
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "Test notification 2",
msg_prefix="Notification should be read")
示例2: testAlertNotifications
# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import save [as 别名]
def testAlertNotifications(self):
"""Test alert."""
alert = UserNotification(recipient=self.user, contents="Alert notification",
display_alert=True)
alert.save()
response = self.client.get(reverse("home_index"))
self.assertContains(response, "notification-dialog", msg_prefix="Alert should be shown")
response = self.client.get(reverse("help_index"))
self.assertNotContains(response, "notification-dialog",
msg_prefix="Dialog should not be displayed")
示例3: testAjaxReadNotifications
# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import save [as 别名]
def testAjaxReadNotifications(self):
"""Test that notifications can be marked as read via AJAX."""
notification = UserNotification(recipient=self.user, contents="Test notification")
notification.save()
response = self.client.post(reverse("notifications_read", args=(notification.pk,)), {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.failUnlessEqual(response.status_code, 200)
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "Test notification",
msg_prefix="Notification should be read")
示例4: testShowNotifications
# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import save [as 别名]
def testShowNotifications(self):
"""
Test that we can show notifications to the user.
"""
for i in range(0, 3):
notification = UserNotification(recipient=self.user,
contents="Test notification %i" % i)
notification.save()
response = self.client.get(reverse("home_index"))
self.assertNotContains(response, "The following item(s) need your attention",
msg_prefix="Alert should not be shown"
)
for i in range(0, 3):
self.assertContains(response, "Test notification %i" % i,
msg_prefix="Notification %i is not shown" % i
)
示例5: testGetUnread
# 需要导入模块: from apps.widgets.notifications.models import UserNotification [as 别名]
# 或者: from apps.widgets.notifications.models.UserNotification import save [as 别名]
def testGetUnread(self):
"""Test that we can get the user's unread notifications."""
user = User.objects.create_user("test", "[email protected]")
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.")