diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 9b73d9f9c..30a586ba4 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -132,7 +132,7 @@ def sort_feed_items(items, order): if order == 'newestFirst': reverse = True try: - sitems = sorted(items, key=lambda i: i['published'], reverse=reverse) + sitems = sorted(items, key=lambda i: i['published_parsed'], reverse=reverse) except KeyError: # feedparser normalizes required timestamp fields in ATOM and RSS # to the "published" field. Feeds missing it are unsortable by date. diff --git a/plugins/RSS/test.py b/plugins/RSS/test.py index 24474a44d..ab26d69e8 100644 --- a/plugins/RSS/test.py +++ b/plugins/RSS/test.py @@ -69,7 +69,35 @@ class RSSTestCase(ChannelPluginTestCase): finally: self.assertNotError('rss remove xkcd') - def testInitialAnnounce(self): + def testInitialAnnounceNewest(self): + old_open = feedparser._open_resource + feedparser._open_resource = constant(xkcd_new) + try: + with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1): + with conf.supybot.plugins.RSS.sortFeedItems.context('newestFirst'): + self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') + self.assertNotError('rss announce add xkcd') + self.assertRegexp(' ', 'Snake Facts') + finally: + self._feedMsg('rss announce remove xkcd') + self._feedMsg('rss remove xkcd') + feedparser._open_resource = old_open + + def testInitialAnnounceOldest(self): + old_open = feedparser._open_resource + feedparser._open_resource = constant(xkcd_new) + try: + with conf.supybot.plugins.RSS.initialAnnounceHeadlines.context(1): + with conf.supybot.plugins.RSS.sortFeedItems.context('oldestFirst'): + self.assertNotError('rss add xkcd http://xkcd.com/rss.xml') + self.assertNotError('rss announce add xkcd') + self.assertRegexp(' ', 'Chaos') + finally: + self._feedMsg('rss announce remove xkcd') + self._feedMsg('rss remove xkcd') + feedparser._open_resource = old_open + + def testNoInitialAnnounce(self): old_open = feedparser._open_resource feedparser._open_resource = constant(xkcd_old) try: