mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-20 09:29:24 +01:00
Aka: Add test for locked Aka help + bug fixed related to locking and aka use in private.
This commit is contained in:
parent
201cb459d6
commit
b2205bc66d
@ -148,11 +148,11 @@ if sqlalchemy:
|
|||||||
def unlock_aka(self, channel, name, by):
|
def unlock_aka(self, channel, name, by):
|
||||||
db = self.get_db(channel)
|
db = self.get_db(channel)
|
||||||
try:
|
try:
|
||||||
aka = db.query(Alias.alias) \
|
aka = db.query(Alias) \
|
||||||
.filter(Alias.name == name).one()
|
.filter(Alias.name == name).one()
|
||||||
except sqlalchemy.orm.exc.NoResultFound:
|
except sqlalchemy.orm.exc.NoResultFound:
|
||||||
raise AkaError(_('This Aka does not exist'))
|
raise AkaError(_('This Aka does not exist'))
|
||||||
if aka.locked:
|
if not aka.locked:
|
||||||
raise AkaError(_('This Aka is already unlocked.'))
|
raise AkaError(_('This Aka is already unlocked.'))
|
||||||
aka.locked = False
|
aka.locked = False
|
||||||
aka.locked_by = by
|
aka.locked_by = by
|
||||||
@ -219,13 +219,13 @@ class Aka(callbacks.Plugin):
|
|||||||
self._db = AkaDB()
|
self._db = AkaDB()
|
||||||
|
|
||||||
def isCommandMethod(self, name):
|
def isCommandMethod(self, name):
|
||||||
channel = dynamic.channel
|
channel = dynamic.channel or 'global'
|
||||||
return self._db.has_aka(channel, name) or \
|
return self._db.has_aka(channel, name) or \
|
||||||
self._db.has_aka('global', name) or \
|
self._db.has_aka('global', name) or \
|
||||||
self.__parent.isCommandMethod(name)
|
self.__parent.isCommandMethod(name)
|
||||||
|
|
||||||
def listCommands(self):
|
def listCommands(self):
|
||||||
channel = dynamic.channel
|
channel = dynamic.channel or 'global'
|
||||||
return set(self._db.get_aka_list(channel) +
|
return set(self._db.get_aka_list(channel) +
|
||||||
self._db.get_aka_list('global') +
|
self._db.get_aka_list('global') +
|
||||||
self.__parent.listCommands())
|
self.__parent.listCommands())
|
||||||
@ -238,7 +238,7 @@ class Aka(callbacks.Plugin):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
name = name or callbacks.formatCommand(command)
|
name = name or callbacks.formatCommand(command)
|
||||||
channel = dynamic.channel
|
channel = dynamic.channel or 'global'
|
||||||
original = self._db.get_alias(channel, name)
|
original = self._db.get_alias(channel, name)
|
||||||
if not original:
|
if not original:
|
||||||
original = self._db.get_alias('global', name)
|
original = self._db.get_alias('global', name)
|
||||||
@ -289,8 +289,17 @@ class Aka(callbacks.Plugin):
|
|||||||
flexargs = _(' at least')
|
flexargs = _(' at least')
|
||||||
else:
|
else:
|
||||||
flexargs = ''
|
flexargs = ''
|
||||||
doc = format(_('<an alias,%s %n>\n\nAlias for %q.'),
|
try:
|
||||||
flexargs, (biggestDollar, _('argument')), original)
|
lock = self._db.get_aka_lock(channel, name)
|
||||||
|
except AkaError:
|
||||||
|
lock = self._db.get_aka_lock('global', name)
|
||||||
|
(locked, locked_by, locked_at) = lock
|
||||||
|
if locked:
|
||||||
|
lock = ' ' + _('Locked by %s at %s') % (locked_by, locked_at)
|
||||||
|
else:
|
||||||
|
lock = ''
|
||||||
|
doc = format(_('<an alias,%s %n>\n\nAlias for %q.%s'),
|
||||||
|
flexargs, (biggestDollar, _('argument')), original, lock)
|
||||||
f = utils.python.changeFunctionName(f, name, doc)
|
f = utils.python.changeFunctionName(f, name, doc)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
@ -383,12 +392,14 @@ class Aka(callbacks.Plugin):
|
|||||||
Raise=True)
|
Raise=True)
|
||||||
channel = arg
|
channel = arg
|
||||||
try:
|
try:
|
||||||
self._db.lock_aka(channel, name, user)
|
self._db.lock_aka(channel, name, user.name)
|
||||||
except AkaError as e:
|
except AkaError as e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
else:
|
||||||
|
irc.replySuccess()
|
||||||
lock = wrap(lock, [getopts({
|
lock = wrap(lock, [getopts({
|
||||||
'channel': 'somethingWithoutSpaces',
|
'channel': 'somethingWithoutSpaces',
|
||||||
}), 'admin', 'commandName'])
|
}), 'admin', 'user', 'commandName'])
|
||||||
|
|
||||||
def unlock(self, irc, msg, args, optlist, user, name):
|
def unlock(self, irc, msg, args, optlist, user, name):
|
||||||
"""[--channel <#channel>] <alias>
|
"""[--channel <#channel>] <alias>
|
||||||
@ -403,12 +414,14 @@ class Aka(callbacks.Plugin):
|
|||||||
Raise=True)
|
Raise=True)
|
||||||
channel = arg
|
channel = arg
|
||||||
try:
|
try:
|
||||||
self._db.lock_aka(channel, name, user)
|
self._db.unlock_aka(channel, name, user.name)
|
||||||
except AkaError as e:
|
except AkaError as e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
else:
|
||||||
|
irc.replySuccess()
|
||||||
unlock = wrap(unlock, [getopts({
|
unlock = wrap(unlock, [getopts({
|
||||||
'channel': 'somethingWithoutSpaces',
|
'channel': 'somethingWithoutSpaces',
|
||||||
}), 'admin', 'commandName'])
|
}), 'admin', 'user', 'commandName'])
|
||||||
|
|
||||||
Class = Aka
|
Class = Aka
|
||||||
|
|
||||||
|
@ -52,8 +52,7 @@ class FunctionsTest(SupyTestCase):
|
|||||||
self.assertEqual(Aka.findBiggestDollar('foo $1 $3'), 3)
|
self.assertEqual(Aka.findBiggestDollar('foo $1 $3'), 3)
|
||||||
self.assertEqual(Aka.findBiggestDollar('$10 bar $1'), 10)
|
self.assertEqual(Aka.findBiggestDollar('$10 bar $1'), 10)
|
||||||
|
|
||||||
|
class AkaChannelTestCase(ChannelPluginTestCase):
|
||||||
class AkaTestCase(ChannelPluginTestCase):
|
|
||||||
plugins = ('Aka', 'Filter', 'Utilities', 'Format', 'Reply')
|
plugins = ('Aka', 'Filter', 'Utilities', 'Format', 'Reply')
|
||||||
|
|
||||||
def testDoesNotOverwriteCommands(self):
|
def testDoesNotOverwriteCommands(self):
|
||||||
@ -135,5 +134,18 @@ class AkaTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('aka add egg "echo qux"')
|
self.assertNotError('aka add egg "echo qux"')
|
||||||
self.assertResponse('egg', 'baz')
|
self.assertResponse('egg', 'baz')
|
||||||
|
|
||||||
|
class AkaTestCase(PluginTestCase):
|
||||||
|
plugins = ('Aka', 'User')
|
||||||
|
|
||||||
|
def testAkaLockedHelp(self):
|
||||||
|
self.assertNotError('register evil_admin foo')
|
||||||
|
|
||||||
|
self.assertNotError('aka add slashdot foo')
|
||||||
|
self.assertRegexp('help slashdot', "Alias for .*foo")
|
||||||
|
self.assertNotRegexp('help slashdot', 'Locked by')
|
||||||
|
self.assertNotError('aka lock slashdot')
|
||||||
|
self.assertRegexp('help slashdot', 'Locked by evil_admin')
|
||||||
|
self.assertNotError('aka unlock slashdot')
|
||||||
|
self.assertNotRegexp('help slashdot', 'Locked by')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
Reference in New Issue
Block a user