예제 #1
0
    def notifications(self, **kwargs):
        """Yield Notification objects from the Echo extension.

        @keyword format: If specified, notifications will be returned formatted
            this way. Its value is either 'model', 'special' or None. Default
            is 'special'.
        @type format: str or None

        Refer API reference for other keywords.
        """
        params = {
            'action': 'query',
            'meta': 'notifications',
            'notformat': 'special',
        }

        for key, value in kwargs.items():
            params['not' + key] = value

        data = self._simple_request(**params).submit()
        notifications = data['query']['notifications']['list']

        # Support API before 1.27.0-wmf.22
        if hasattr(notifications, 'values'):
            notifications = notifications.values()

        return (Notification.fromJSON(self, notification)
                for notification in notifications)
예제 #2
0
 def test_from_json(self):
     """Test Notification.fromJSON class method and instance attributes."""
     notif = Notification.fromJSON(self.get_site(), self.data)
     self.assertIsInstance(notif, Notification)
     self.assertEqual(notif.site, self.get_site())
     self.assertEqual(str(notif.event_id), self.data['id'])
     self.assertEqual(notif.type, self.data['type'])
     self.assertEqual(notif.category, self.data['category'])
     self.assertIsInstance(notif.timestamp, pywikibot.Timestamp)
     self.assertEqual(notif.timestamp.totimestampformat(),
                      self.data['timestamp']['mw'])
     self.assertIsInstance(notif.agent, pywikibot.User)
     self.assertIsNone(notif.page)
     self.assertEqual(notif.agent.title(with_ns=False),
                      self.data['agent']['name'])
     self.assertFalse(notif.read)
     self.assertEqual(notif.content, self.data['*'])
     self.assertIsNone(notif.revid)