Updated to make the tests pass.

This commit is contained in:
Jeremy Fincher 2004-01-31 22:04:46 +00:00
parent 4a4aa6ec27
commit 7f2578a13e
2 changed files with 11 additions and 10 deletions

View File

@ -81,7 +81,7 @@ conf.registerChannelValue(conf.supybot.plugins.URL, 'tinyurlSnarfer',
supybot.plugins.URL.tinyurlSnarfer.minimumLength) it will post a smaller supybot.plugins.URL.tinyurlSnarfer.minimumLength) it will post a smaller
from tinyurl.com.""")) from tinyurl.com."""))
conf.registerChannelValue(conf.supybot.plugins.URL.tinyurlSnarfer, conf.registerChannelValue(conf.supybot.plugins.URL.tinyurlSnarfer,
'maximumLength', 'minimumLength',
registry.PositiveInteger(48, """The minimum length a URL must be before the registry.PositiveInteger(48, """The minimum length a URL must be before the
tinyurl snarfer will snarf it.""")) tinyurl snarfer will snarf it."""))
conf.registerChannelValue(conf.supybot.plugins.URL, 'titleSnarfer', conf.registerChannelValue(conf.supybot.plugins.URL, 'titleSnarfer',
@ -173,7 +173,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
channel = msg.args[0] channel = msg.args[0]
if self.registryValue('tinyurlSnarfer', channel): if self.registryValue('tinyurlSnarfer', channel):
url = match.group(0) url = match.group(0)
minlen = self.registryValue('tinyurlSnarfer.maximumLength',channel) minlen = self.registryValue('tinyurlSnarfer.minimumLength',channel)
if len(url) >= minlen: if len(url) >= minlen:
db = self.getDb(channel) db = self.getDb(channel)
cursor = db.cursor() cursor = db.cursor()
@ -245,7 +245,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
return (tinyurl, updateDb) return (tinyurl, updateDb)
def _formatUrl(self, url, added, addedBy): def _formatUrl(self, url, added, addedBy):
when = time.strftime(conf.supybot.supybot.humanTimestampFormat(), when = time.strftime(conf.supybot.humanTimestampFormat(),
time.localtime(int(added))) time.localtime(int(added)))
return '<%s> (added by %s at %s)' % (url, addedBy, when) return '<%s> (added by %s at %s)' % (url, addedBy, when)
@ -279,7 +279,7 @@ class URL(callbacks.PrivmsgCommandAndRegexp,
return return
channel = msg.args[0] channel = msg.args[0]
snarf = self.registryValue('tinyurlSnarfer', channel) snarf = self.registryValue('tinyurlSnarfer', channel)
minlen = self.registryValue('tinyurlMinimumLength', channel) minlen = self.registryValue('tinyurlSnarfer.minimumLength', channel)
if snarf and len(url) >= minlen: if snarf and len(url) >= minlen:
return return
(tinyurl, updateDb) = self._getTinyUrl(url, channel, cmd=True) (tinyurl, updateDb) = self._getTinyUrl(url, channel, cmd=True)

View File

@ -75,17 +75,17 @@ if sqlite is not None:
class URLTestCase(ChannelPluginTestCase, PluginDocumentation): class URLTestCase(ChannelPluginTestCase, PluginDocumentation):
plugins = ('URL',) plugins = ('URL',)
def setUp(self): def setUp(self):
ChannelPluginTestCase.setUp(self)
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False) conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
ChannePluginTestCase.setUp(self)
def test(self): def test(self):
counter = 0 counter = 0
self.assertNotError('url random') self.assertNotError('url random')
for url in urls: for url in urls:
self.assertRegexp('url num', str(counter)) self.assertRegexp('url stats', str(counter))
self.feedMsg(url) self.feedMsg(url)
counter += 1 counter += 1
self.assertRegexp('url num', str(counter)) self.assertRegexp('url stats', str(counter))
self.assertRegexp('url last', re.escape(urls[-1])) self.assertRegexp('url last', re.escape(urls[-1]))
self.assertRegexp('url last --proto https', re.escape(urls[-3])) self.assertRegexp('url last --proto https', re.escape(urls[-3]))
self.assertRegexp('url last --at gameknot.com',re.escape(urls[-2])) self.assertRegexp('url last --at gameknot.com',re.escape(urls[-2]))
@ -132,11 +132,11 @@ if sqlite is not None:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True) conf.supybot.plugins.URL.tinyurlSnarfer.setValue(True)
self.assertRegexp('http://sourceforge.net/tracker/?' self.assertRegexp('http://sourceforge.net/tracker/?'
'func=add&group_id=58965&atid=489447', 'func=add&group_id=58965&atid=489447',
r'http://tinyurl.com/rqac.* \(was') r'http://tinyurl.com/rqac.* \(at')
self.assertRegexp( self.assertRegexp(
'http://www.urbandictionary.com/define.php?' 'http://www.urbandictionary.com/define.php?'
'term=all+your+base+are+belong+to+us', 'term=all+your+base+are+belong+to+us',
r'http://tinyurl.com/u479.* \(was') r'http://tinyurl.com/u479.* \(at')
finally: finally:
conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False) conf.supybot.plugins.URL.tinyurlSnarfer.setValue(False)
@ -144,7 +144,8 @@ if sqlite is not None:
try: try:
conf.supybot.plugins.URL.titleSnarfer.setValue(True) conf.supybot.plugins.URL.titleSnarfer.setValue(True)
self.assertResponse('http://microsoft.com/', self.assertResponse('http://microsoft.com/',
'Title: Microsoft Corporation') 'Title: Microsoft Corporation'
' (at microsoft.com)')
finally: finally:
conf.supybot.plugins.URL.titleSnarfer.setValue(False) conf.supybot.plugins.URL.titleSnarfer.setValue(False)