Beispiel #1
0
    def test_12_python_actions(self):
        """Test Python API with actions"""
        self.assertEquals(self.nm.notificationCount, 0)
        nm = UnwrapObject(self.nm)
        a0_data = {
            "identifier": "action0",
            "label": "action0-label",
            "accessKey": "a",
            "iconURL": "action-url",
            "visible": True,
            "enabled": True
        }
        notif = nm.add("summary", ["tags"],
                       "notif-action-py",
                       actions=[a0_data])
        self.assertEquals(notif,
                          self._wrap(notif))  # should already be wrapped
        notif.QueryInterface(Ci.koINotification)  # should implement this
        notif.QueryInterface(Ci.koINotificationActionable)  # due to actions=
        self.assertEquals(self.nm.notificationCount,
                          1)  # added one notification
        try:
            self.assertEquals(len(notif.getActions()), 1)
            self.assertEquals(len(notif.getActions("bad-id")), 0)
            self.assertEquals(len(notif.getActions("action0")), 1)
            action = notif.getActions()[0]
            self.assertEquals(action, self._wrap(action))
            for k, v in a0_data.items():
                self.assertEquals(getattr(action, k), v)
            for k in ("label", "accessKey", "iconURL"):
                with self.check_called(notif, will_call=False):
                    # changing the action won't force an update
                    self.assertNotEquals(getattr(action, k), k)
                    setattr(action, k, k)
                    self.assertEquals(getattr(action, k), k)
            with self.check_called(notif, old_index=0, new_index=0):
                # calling the right update API, however, will fire listeners
                nm.update(notif,
                          actions=[{
                              "identifier": "action0",
                              "label": "new label"
                          }])
                self.assertEquals(action.label, "new label")
            self.assertRaises(COMException,
                              nm.update,
                              notif,
                              actions=[{
                                  "label": "foo"
                              }])
            self.assertRaises(COMException,
                              nm.update,
                              notif,
                              actions=[{
                                  "identifier": "action0",
                                  "invalid": "key"
                              }])

        finally:
            nm.remove(notif)
            self.assertEquals(self.nm.notificationCount, 0)
    def test_12_python_actions(self):
        """Test Python API with actions"""
        self.assertEquals(self.nm.notificationCount, 0)
        nm = UnwrapObject(self.nm)
        a0_data = { "identifier": "action0",
                    "label": "action0-label",
                    "accessKey": "a",
                    "iconURL": "action-url",
                    "visible": True,
                    "enabled": True }
        notif = nm.add("summary", ["tags"], "notif-action-py", actions=[a0_data])
        self.assertEquals(notif, self._wrap(notif)) # should already be wrapped
        notif.QueryInterface(Ci.koINotification) # should implement this
        notif.QueryInterface(Ci.koINotificationActionable) # due to actions=
        self.assertEquals(self.nm.notificationCount, 1) # added one notification
        try:
            self.assertEquals(len(notif.getActions()), 1)
            self.assertEquals(len(notif.getActions("bad-id")), 0)
            self.assertEquals(len(notif.getActions("action0")), 1)
            action = notif.getActions()[0]
            self.assertEquals(action, self._wrap(action))
            for k, v in a0_data.items():
                self.assertEquals(getattr(action, k), v)
            for k in ("label", "accessKey", "iconURL"):
                with self.check_called(notif, will_call=False):
                    # changing the action won't force an update
                    self.assertNotEquals(getattr(action, k), k)
                    setattr(action, k, k)
                    self.assertEquals(getattr(action, k), k)
            with self.check_called(notif, old_index=0, new_index=0):
                # calling the right update API, however, will fire listeners
                nm.update(notif, actions=[{ "identifier": "action0",
                                            "label": "new label"}])
                self.assertEquals(action.label, "new label")
            self.assertRaises(COMException,
                              nm.update, notif, actions=[{"label": "foo"}])
            self.assertRaises(COMException,
                              nm.update, notif, actions=[{"identifier": "action0",
                                                          "invalid": "key"}])

        finally:
            nm.remove(notif)
            self.assertEquals(self.nm.notificationCount, 0)
Beispiel #3
0
    def test_11_python_interface(self):
        """Test the more Python API"""
        self.assertEquals(self.nm.notificationCount, 0)
        nm = UnwrapObject(self.nm)
        kwargs = {
            "iconURL": "icon URL",
            "severity": Ci.koINotification.SEVERITY_WARNING,
            "description": "description",
            "details": "details",
            "maxProgress": 10,
            "progress": 5
        }
        notif = nm.add("summary", ["tags"], "notif-ident", **kwargs)
        try:
            self.assertEquals(notif,
                              self._wrap(notif))  # should already be wrapped
            notif.QueryInterface(Ci.koINotification)  # should implement this
            notif.QueryInterface(
                Ci.koINotificationProgress)  # due to maxProgress
            notif.QueryInterface(Ci.koINotificationText)  # due to details
            self.assertEquals(notif.summary, "summary")
            self.assertEquals(notif.getTags(), ["tags"])
            self.assertEquals(notif.identifier, "notif-ident")
            self.assertEquals(self.nm.notificationCount,
                              1)  # added one notification

            notif2 = nm.add("modified-summary", [], "notif-ident")
            self.assertEquals(notif, notif2)  # no context, same identifier
            self.assertEquals(notif.summary,
                              "modified-summary")  # got the new one
            self.assertEquals(notif.getTags(), ["tags"])  # kept the old one

            for k, v in kwargs.items():
                self.assertEquals(getattr(notif, k), v)
            updates = {
                "summary": "new summary",
                "details": "new details",
                "progress": 2
            }
            nm.update(notif, **updates)
            for k, v in updates.items():
                self.assertEquals(getattr(notif, k), v)
            self.assertRaises(COMException, nm.update, notif, progress=20)

            # check listeners get hooked up correctly
            called = set()

            def listener(aNotification, aOldIndex, aNewIndex, aReason):
                self.assertEquals(aNotification, notif)
                self.assertEquals(aOldIndex, 0)
                self.assertEquals(aNewIndex, 0)
                self.assertEquals(aReason,
                                  Ci.koINotificationListener.REASON_UPDATED)
                called.add(True)

            nm.addListener(listener)
            notif.progress = 9
            self._waitForCompletion()
            self.assertTrue(
                called,
                "expected listener to be called due to progress change")
            nm.removeListener(listener)
            called.discard(True)
            notif.progress = 10
            self._waitForCompletion()
            self.assertFalse(
                called,
                "did not expect listener to be called because it was removed")

            # test python iterable
            self.assertEquals(len(nm), 1)
            self.assertEquals(nm[0], notif)
            self.assertEquals([x for x in nm], [notif])
            self.assertTrue(notif in nm)
            self.assertEquals(nm.count(notif), 1)
            self.assertEquals(nm.index(notif), 0)

        finally:
            nm.remove(notif)
            self.assertEquals(self.nm.notificationCount, 0)
    def test_11_python_interface(self):
        """Test the more Python API"""
        self.assertEquals(self.nm.notificationCount, 0)
        nm = UnwrapObject(self.nm)
        kwargs = { "iconURL": "icon URL",
                   "severity": Ci.koINotification.SEVERITY_WARNING,
                   "description": "description",
                   "details": "details",
                   "maxProgress": 10,
                   "progress": 5 }
        notif = nm.add("summary", ["tags"], "notif-ident", **kwargs)
        try:
            self.assertEquals(notif, self._wrap(notif)) # should already be wrapped
            notif.QueryInterface(Ci.koINotification) # should implement this
            notif.QueryInterface(Ci.koINotificationProgress) # due to maxProgress
            notif.QueryInterface(Ci.koINotificationText) # due to details
            self.assertEquals(notif.summary, "summary")
            self.assertEquals(notif.getTags(), ["tags"])
            self.assertEquals(notif.identifier, "notif-ident")
            self.assertEquals(self.nm.notificationCount, 1) # added one notification

            notif2 = nm.add("modified-summary", [], "notif-ident")
            self.assertEquals(notif, notif2) # no context, same identifier
            self.assertEquals(notif.summary, "modified-summary") # got the new one
            self.assertEquals(notif.getTags(), ["tags"]) # kept the old one

            for k, v in kwargs.items():
                self.assertEquals(getattr(notif, k), v)
            updates = { "summary": "new summary",
                        "details": "new details",
                        "progress": 2 }
            nm.update(notif, **updates)
            for k, v in updates.items():
                self.assertEquals(getattr(notif, k), v)
            self.assertRaises(COMException,
                              nm.update, notif, progress=20)

            # check listeners get hooked up correctly
            # No longer tested as notification changes do not notify listeners.
            #called = set()
            #def listener(aNotification, aOldIndex, aNewIndex, aReason):
            #    self.assertEquals(aNotification, notif)
            #    self.assertEquals(aOldIndex, 0)
            #    self.assertEquals(aNewIndex, 0)
            #    self.assertEquals(aReason, Ci.koINotificationListener.REASON_UPDATED)
            #    called.add(True)
            #nm.addListener(listener)
            #notif.progress = 9
            #self._waitForCompletion()
            #self.assertTrue(called, "expected listener to be called due to progress change")
            #nm.removeListener(listener)
            #called.discard(True)
            #notif.progress = 10
            #self._waitForCompletion()
            #self.assertFalse(called, "did not expect listener to be called because it was removed")

            # test python iterable
            self.assertEquals(len(nm), 1)
            self.assertEquals(nm[0], notif)
            self.assertEquals([x for x in nm], [notif])
            self.assertTrue(notif in nm)
            self.assertEquals(nm.count(notif), 1)
            self.assertEquals(nm.index(notif), 0)

        finally:
            nm.remove(notif)
            self.assertEquals(self.nm.notificationCount, 0)