mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +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)
|
s += " Locked by %s on %s." % (lock_by, lock_at)
|
||||||
irc.reply(s)
|
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:
|
try:
|
||||||
id = ircdb.users.getUserId(msg.prefix)
|
id = ircdb.users.getUserId(msg.prefix)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
irc.errorNotRegistered()
|
irc.errorNotRegistered()
|
||||||
return
|
return
|
||||||
|
self.log.debug('id: %s' % id)
|
||||||
key = privmsgs.getArgs(args, required=1)
|
key = privmsgs.getArgs(args, required=1)
|
||||||
db = self.dbHandler.getDb()
|
db = self.dbHandler.getDb()
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
@ -475,24 +477,25 @@ class MoobotFactoids(callbacks.PrivmsgCommandAndRegexp):
|
|||||||
return
|
return
|
||||||
(created_by, locked_by) = cursor.fetchone()
|
(created_by, locked_by) = cursor.fetchone()
|
||||||
# Don't perform redundant operations
|
# Don't perform redundant operations
|
||||||
if lock:
|
if locking and locked_by is not None:
|
||||||
if locked_by is not None:
|
|
||||||
irc.error('Factoid "%s" is already locked.' % key)
|
irc.error('Factoid "%s" is already locked.' % key)
|
||||||
return
|
return
|
||||||
else:
|
if not locking and locked_by is None:
|
||||||
if locked_by is None:
|
|
||||||
irc.error('Factoid "%s" is not locked.' % key)
|
irc.error('Factoid "%s" is not locked.' % key)
|
||||||
return
|
return
|
||||||
# Can only lock/unlock own factoids unless you're an admin
|
# 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):
|
if not (ircdb.checkCapability(id, 'admin') or created_by == id):
|
||||||
s = "unlock"
|
if locking:
|
||||||
if lock:
|
|
||||||
s = "lock"
|
s = "lock"
|
||||||
|
else:
|
||||||
|
s = "unlock"
|
||||||
irc.error("Cannot %s someone else's factoid unless you "
|
irc.error("Cannot %s someone else's factoid unless you "
|
||||||
"are an admin." % s)
|
"are an admin." % s)
|
||||||
return
|
return
|
||||||
# Okay, we're done, ready to lock/unlock
|
# Okay, we're done, ready to lock/unlock
|
||||||
if lock:
|
if locking:
|
||||||
locked_at = int(time.time())
|
locked_at = int(time.time())
|
||||||
else:
|
else:
|
||||||
locked_at = None
|
locked_at = None
|
||||||
|
@ -164,6 +164,10 @@ if sqlite is not None:
|
|||||||
'(?!(request|modif)).*?\.$')
|
'(?!(request|modif)).*?\.$')
|
||||||
|
|
||||||
def testLockUnlock(self):
|
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('moo is <reply>moo')
|
||||||
self.assertNotError('lock moo')
|
self.assertNotError('lock moo')
|
||||||
self.assertRegexp('factinfo moo',
|
self.assertRegexp('factinfo moo',
|
||||||
@ -182,6 +186,8 @@ if sqlite is not None:
|
|||||||
self.assertNotError('unlock moo')
|
self.assertNotError('unlock moo')
|
||||||
self.assertRegexp('factinfo moo',
|
self.assertRegexp('factinfo moo',
|
||||||
'^moo: Created by tester on.*?\.')
|
'^moo: Created by tester on.*?\.')
|
||||||
|
finally:
|
||||||
|
world.testing = True
|
||||||
|
|
||||||
def testChangeFactoid(self):
|
def testChangeFactoid(self):
|
||||||
self.assertNotError('moo is <reply>moo')
|
self.assertNotError('moo is <reply>moo')
|
||||||
@ -240,7 +246,10 @@ if sqlite is not None:
|
|||||||
def testListkeys(self):
|
def testListkeys(self):
|
||||||
self.assertResponse('listkeys %', 'No keys matching "%" found.')
|
self.assertResponse('listkeys %', 'No keys matching "%" found.')
|
||||||
self.assertNotError('moo is <reply>moo')
|
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 moo', 'moo')
|
||||||
self.assertResponse('listkeys foo', 'No keys matching "foo" '
|
self.assertResponse('listkeys foo', 'No keys matching "foo" '
|
||||||
'found.')
|
'found.')
|
||||||
|
Loading…
Reference in New Issue
Block a user