mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
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:
parent
f3c481d13f
commit
a35e185c4b
@ -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:
|
||||
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
|
||||
|
@ -164,6 +164,10 @@ if sqlite is not None:
|
||||
'(?!(request|modif)).*?\.$')
|
||||
|
||||
def testLockUnlock(self):
|
||||
# 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',
|
||||
@ -182,6 +186,8 @@ if sqlite is not None:
|
||||
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.')
|
||||
|
Loading…
Reference in New Issue
Block a user