mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
RSS: Make sure two different feeds cannot have the same URL.
This commit is contained in:
parent
3a127e884e
commit
057da44ab3
@ -167,10 +167,17 @@ class RSS(callbacks.Plugin):
|
||||
##################
|
||||
# Feed registering
|
||||
|
||||
def assert_feed_does_not_exist(self, name):
|
||||
def assert_feed_does_not_exist(self, name, url=None):
|
||||
if self.isCommandMethod(name):
|
||||
s = format('I already have a command in this plugin named %s.',name)
|
||||
s = format(_('I already have a command in this plugin named %s.'),
|
||||
name)
|
||||
raise callbacks.Error(s)
|
||||
if url:
|
||||
feed = self.feeds.get(url)
|
||||
if feed and feed.name != feed.url:
|
||||
s = format(_('I already have a feed with that URL named %s.'),
|
||||
feed.name)
|
||||
raise callbacks.Error(s)
|
||||
|
||||
def register_feed_config(self, name, url=''):
|
||||
self.registryValue('feeds').add(name)
|
||||
@ -332,7 +339,7 @@ class RSS(callbacks.Plugin):
|
||||
Adds a command to this plugin that will look up the RSS feed at the
|
||||
given URL.
|
||||
"""
|
||||
self.assert_feed_does_not_exist(name)
|
||||
self.assert_feed_does_not_exist(name, url)
|
||||
self.register_feed_config(name, url)
|
||||
self.register_feed(name, url, False)
|
||||
irc.replySuccess()
|
||||
|
@ -62,6 +62,13 @@ class RSSTestCase(ChannelPluginTestCase):
|
||||
def testCantRemoveMethodThatIsntFeed(self):
|
||||
self.assertError('rss remove rss')
|
||||
|
||||
def testCantAddDuplicatedFeed(self):
|
||||
self.assertNotError('rss add xkcd http://xkcd.com/rss.xml')
|
||||
try:
|
||||
self.assertError('rss add xkcddup http://xkcd.com/rss.xml')
|
||||
finally:
|
||||
self.assertNotError('rss remove xkcd')
|
||||
|
||||
def testAnnounce(self):
|
||||
old_open = feedparser._open_resource
|
||||
feedparser._open_resource = constant(xkcd_old)
|
||||
|
Loading…
Reference in New Issue
Block a user