Just changed a var name to be more clear in _lock for MF, and finally fixed the

MF tests so that they all pass (without removing test functionality)!
This commit is contained in:
Daniel DiPaolo 2004-02-17 06:33:23 +00:00
parent f3c481d13f
commit a35e185c4b
2 changed files with 40 additions and 28 deletions

View File

@ -459,12 +459,14 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
s += " Locked by %s on %s." % (lock_by, lock_at)
irc.reply(s)
def _lock(self, irc, msg, args, lock=True):
def _lock(self, irc, msg, args, locking=True):
self.log.debug('in _lock')
try:
id = ircdb.users.getUserId(msg.prefix)
except KeyError:
irc.errorNotRegistered()
return
self.log.debug('id: %s' % id)
key = privmsgs.getArgs(args, required=1)
db = self.dbHandler.getDb()
cursor = db.cursor()
@ -475,24 +477,25 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
return
(created_by, locked_by) = cursor.fetchone()
# Don't perform redundant operations
if lock:
if locked_by is not None:
if locking and locked_by is not None:
irc.error('Factoid "%s" is already locked.' % key)
return
else:
if locked_by is None:
if not locking and locked_by is None:
irc.error('Factoid "%s" is not locked.' % key)
return
# Can only lock/unlock own factoids unless you're an admin
self.log.debug('admin?: %s' % ircdb.checkCapability(id, 'admin'))
self.log.debug('created_by: %s' % created_by)
if not (ircdb.checkCapability(id, 'admin') or created_by == id):
s = "unlock"
if lock:
s = "lock"
if locking:
s = "lock"
else:
s = "unlock"
irc.error("Cannot %s someone else's factoid unless you "
"are an admin." % s)
return
# Okay, we're done, ready to lock/unlock
if lock:
if locking:
locked_at = int(time.time())
else:
locked_at = None

View File

@ -164,24 +164,30 @@ if sqlite is not None:
'(?!(request|modif)).*?\.$')
def testLockUnlock(self):
self.assertNotError('moo is <reply>moo')
self.assertNotError('lock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on'
'.*?\. Locked by tester on .*?\.')
# switch user
self.prefix = 'moo!moo@moo'
self.assertNotError('register nottester moo')
self.assertError('unlock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on'
'.*?\. Locked by tester on .*?\.')
# switch back
self.prefix = 'foo!bar@baz'
self.assertNotError('identify tester moo')
self.assertNotError('unlock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on.*?\.')
# disable world.testing since we want new users to not
# magically be endowed with the admin capability
try:
world.testing = False
self.assertNotError('moo is <reply>moo')
self.assertNotError('lock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on'
'.*?\. Locked by tester on .*?\.')
# switch user
self.prefix = 'moo!moo@moo'
self.assertNotError('register nottester moo')
self.assertError('unlock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on'
'.*?\. Locked by tester on .*?\.')
# switch back
self.prefix = 'foo!bar@baz'
self.assertNotError('identify tester moo')
self.assertNotError('unlock moo')
self.assertRegexp('factinfo moo',
'^moo: Created by tester on.*?\.')
finally:
world.testing = True
def testChangeFactoid(self):
self.assertNotError('moo is <reply>moo')
@ -240,7 +246,10 @@ if sqlite is not None:
def testListkeys(self):
self.assertResponse('listkeys %', 'No keys matching "%" found.')
self.assertNotError('moo is <reply>moo')
# If only one key, it should respond with the factoid
# With this set, if only one key matches, it should respond with
# the factoid
MFconf = conf.supybot.plugins.MoobotFactoids # looooong!
MFconf.showFactoidIfOnlyOneMatch.setValue(True)
self.assertResponse('listkeys moo', 'moo')
self.assertResponse('listkeys foo', 'No keys matching "foo" '
'found.')