More MoobotFactoids/Dunno separation fun and fixes

This commit is contained in:
Daniel DiPaolo 2003-10-28 05:31:51 +00:00
parent 3db33b5ef3
commit 084fe1854f
4 changed files with 84 additions and 25 deletions

View File

@ -33,6 +33,9 @@
Add the module docstring here. This will be used by the setup.py script.
"""
import os
import conf
import time
import ircdb
import sqlite
import plugins
@ -56,7 +59,7 @@ Add an example IRC session using this module here.
""")
class Dunno(callbacks.Privmsg):
priority = 1000
priority = 100
def __init__(self):
callbacks.Privmsg.__init__(self)
self.makeDb(dbfilename)
@ -153,12 +156,12 @@ class Dunno(callbacks.Privmsg):
if cursor.rowcount == 0:
irc.error(msg, 'No dunnos with %r found.' % text)
return
ids = cursor.fetchall()
ids = [str(tup[0]) for tup in cursor.fetchall()]
s = "Dunno search for %r (%d found): %s" % \
(text, len(ids), utils.commaAndify(ids))
irc.reply(msg, s)
def dunno(self, irc, msg, args):
def get(self, irc, msg, args):
"""<id>
Display the text of the dunno with the given id.

View File

@ -124,7 +124,7 @@ def pick(L, recursed=False):
return L
class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
priority = 999
priority = 98
addressedRegexps = ['changeFactoid', 'augmentFactoid',
'replaceFactoid', 'addFactoid']
def __init__(self):
@ -158,10 +158,6 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
self.db.commit()
self.db.close()
del self.db
# Recover from clobbering this command earlier
Misc = Owner.loadPluginModule('Misc')
Misc.replyWhenNotCommand = self.originalReplyWhenNotCommand
conf.replyWhenNotCommand = self.originalConfReplyWhenNotCommand
def parseFactoid(self, fact):
type = "define" # Default is to just spit the factoid back as a

76
test/test_Dunno.py Normal file
View File

@ -0,0 +1,76 @@
#!/usr/bin/env python
###
# Copyright (c) 2003, Daniel DiPaolo
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from test import *
try:
import sqlite
except ImportError:
sqlite = None
if sqlite is not None:
class DunnoTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Dunno', 'User')
def setUp(self):
PluginTestCase.setUp(self)
self.prefix = 'foo!bar@baz'
self.assertNotError('register tester moo')
def testDunnoAdd(self):
self.assertNotError('dunno add moo')
self.assertResponse('asdfagagfosdfk', 'moo')
def testDunnoRemove(self):
self.assertNotError('dunno add moo')
self.assertNotError('dunno remove 1')
def testDunnoSearch(self):
self.assertNotError('dunno add foo')
self.assertError('dunno search moo')
self.assertNotError('dunno add moo')
self.assertResponse('dunno search moo', 'Dunno search for \'moo\' '
'(1 found): 2')
self.assertResponse('dunno search m', 'Dunno search for \'m\' '
'(1 found): 2')
# Test multiple adds
for i in range(5):
self.assertNotError('dunno add moo%s' % i)
self.assertResponse('dunno search moo',
'Dunno search for \'moo\' (6 found): '
'2, 3, 4, 5, 6, and 7')
def testDunnoGet(self):
self.assertNotError('dunno add moo')
self.assertResponse('dunno get 1', 'Dunno #1: \'moo\'')
self.assertNotError('dunno add $who')
self.assertResponse('dunno get 2', 'Dunno #2: \'$who\'')
self.assertError('dunno get 3')
self.assertError('dunno get a')

View File

@ -38,14 +38,12 @@ except ImportError:
if sqlite is not None:
class FactoidsTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Misc', 'MoobotFactoids', 'User', 'Utilities')
plugins = ('MoobotFactoids', 'User', 'Utilities')
def setUp(self):
PluginTestCase.setUp(self)
# Create a valid user to use
self.prefix = 'foo!bar@baz'
self.assertNotError('register tester moo')
self.assertNotError('dunnoadd not moo') # don't change to "moo"
# or testDelete will fail
def testLiteral(self):
self.assertError('literal moo') # no factoids yet
@ -201,19 +199,5 @@ if sqlite is not None:
self.failIf(m)
class DunnoTestCase(PluginTestCase, PluginDocumentation):
plugins = ('Misc', 'MoobotFactoids', 'User')
def setUp(self):
PluginTestCase.setUp(self)
self.prefix = 'foo!bar@baz'
self.assertNotError('register tester moo')
def testDunnoAdd(self):
self.assertNotError('dunnoadd moo')
self.assertResponse('asdfagagfosdfk', 'moo')
def testDunnoRemove(self):
self.assertNotError('dunnoadd moo')
self.assertNotError('dunnoremove 1')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: