Exemplo n.º 1
0
    def test_on_listen_for_notification_up_calls(self):
        super_on_listen = self.patch(Handler, "on_listen")
        super_on_listen.return_value = sentinel.on_listen

        user = factory.make_User()
        handler = NotificationHandler(user, {})

        self.assertThat(
            handler.on_listen("notification", sentinel.action, sentinel.pk),
            Is(sentinel.on_listen))
        self.assertThat(
            super_on_listen,
            MockCalledOnceWith("notification", sentinel.action, sentinel.pk))
Exemplo n.º 2
0
    def test_on_listen_for_dismissal_up_calls_with_delete(self):
        super_on_listen = self.patch(Handler, "on_listen")
        super_on_listen.return_value = sentinel.on_listen

        user = factory.make_User()
        handler = NotificationHandler(user, {})
        notification = factory.make_Notification(user=user)

        # A dismissal notification from the database.
        dismissal = "%d:%d" % (notification.id, user.id)

        self.assertThat(
            handler.on_listen("notificationdismissal", sentinel.action,
                              dismissal), Is(sentinel.on_listen))
        self.assertThat(
            super_on_listen,
            MockCalledOnceWith("notification", "delete", notification.id))
Exemplo n.º 3
0
 def test_not_dismissable(self):
     user = factory.make_User()
     handler = NotificationHandler(user, {}, None)
     notification = factory.make_Notification(user=user, dismissable=False)
     self.assertRaises(
         NotificationNotDismissable,
         handler.dismiss,
         {"id": str(notification.id)},
     )