MoobotFactoids.randomfactoid must've felt so lonely not having anyone to test

that he was ok.  Add that to him having an unwanted msg lying around, and he
must've been quite sad.
This commit is contained in:
James Vega 2004-02-17 21:41:52 +00:00
parent 1ef546178c
commit 3128255c0f
2 changed files with 9 additions and 3 deletions

View File

@ -681,14 +681,15 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
Displays a random factoid (along with its key) from the database. Displays a random factoid (along with its key) from the database.
""" """
cursor = self.db.cursor() db = self.dbHandler.getDb()
cursor = db.cursor()
cursor.execute("""SELECT fact, key FROM factoids cursor.execute("""SELECT fact, key FROM factoids
ORDER BY random() LIMIT 1""") ORDER BY random() LIMIT 1""")
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error(msg, 'No factoids in the database.') irc.error('No factoids in the database.')
return return
(fact, key) = cursor.fetchone() (fact, key) = cursor.fetchone()
irc.reply(msg, 'Random factoid: "%s" is "%s"' % (key, fact)) irc.reply('Random factoid: "%s" is "%s"' % (key, fact))
Class = MoobotFactoids Class = MoobotFactoids

View File

@ -340,5 +340,10 @@ if sqlite is not None:
self.assertResponse('listkeys foo', 'Key search for "foo" ' self.assertResponse('listkeys foo', 'Key search for "foo" '
'(1 found): "foo"') '(1 found): "foo"')
def testRandomFactoid(self):
self.assertNotError('foo is <reply>bar')
self.assertNotError('bar is <reply>baz')
self.assertRegexp('randomfactoid', r'bar|baz')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: