RSS: Make @remove completely clean up feeds

This commit is contained in:
Valentin Lorentz 2021-05-01 14:29:09 +02:00
parent 556bd788b5
commit 97a7aa304e
2 changed files with 15 additions and 9 deletions

View File

@ -290,11 +290,17 @@ class RSS(callbacks.Plugin):
self.feeds[url] = Feed(name, url, initial,
plugin_is_loading, announced)
def remove_feed(self, feed):
del self.feed_names[feed.name]
del self.feeds[feed.url]
conf.supybot.plugins.RSS.feeds().remove(feed.name)
conf.supybot.plugins.RSS.feeds.unregister(feed.name)
def remove_feed(self, name_or_url):
self.feed_names.pop(name_or_url, None)
while True:
try:
conf.supybot.plugins.RSS.feeds().remove(name_or_url)
except KeyError:
break
try:
conf.supybot.plugins.RSS.feeds.unregister(name_or_url)
except (KeyError, registry.NonExistentRegistryEntry):
pass
##################
# Methods handling
@ -517,7 +523,6 @@ class RSS(callbacks.Plugin):
if not feed:
irc.error(_('That\'s not a valid RSS feed command name.'))
return
self.remove_feed(feed)
# If the feed was first created "anonymously", eg. with
# `@rss announce add http://example.org/rss`, then as a named feed
@ -525,8 +530,8 @@ class RSS(callbacks.Plugin):
# `self.get_feed(name)` above gets only one of them; so let's
# remove the aliased name or URL from the feed names too,
# or we would have a dangling entry here.
self.feed_names.pop(name, None)
self.feed_names.pop(feed.url, None)
self.remove_feed(feed.url)
self.remove_feed(name)
assert self.get_feed(name) is None
irc.replySuccess()

View File

@ -109,7 +109,6 @@ class RSSTestCase(ChannelPluginTestCase):
self.assertNotError('rss announce remove http://xkcd.com/rss.xml')
self.assertNotError('rss remove xkcd')
self.assertEqual(self.irc.getCallback('RSS').feed_names, {})
self.assertEqual(self.irc.getCallback('RSS').feeds, {})
@mock_urllib
def testInitialAnnounceNewest(self, mock):
@ -213,6 +212,8 @@ class RSSTestCase(ChannelPluginTestCase):
self.assertNoResponse(' ', timeout=0.1)
timeFastForward(1.1)
self.assertRegexp(' ', 'Telescopes')
self.assertRegexp(' ', 'Chaos')
self.assertNoResponse(' ', timeout=0.1)
finally:
self._feedMsg('rss announce remove http://xkcd.com/rss.xml')
self._feedMsg('rss remove http://xkcd.com/rss.xml')