Admin capability add/remove refactored, and tests changed accordingly.

This commit is contained in:
Ali Afshar 2005-03-25 13:41:17 +00:00
parent 71830d0c84
commit 890d92df0e
2 changed files with 66 additions and 54 deletions

View File

@ -237,7 +237,9 @@ class Admin(callbacks.Plugin):
irc.replySuccess() irc.replySuccess()
part = wrap(part, [optional('validChannel'), additional('text')]) part = wrap(part, [optional('validChannel'), additional('text')])
def addcapability(self, irc, msg, args, user, capability): class capability(callbacks.Commands):
def add(self, irc, msg, args, user, capability):
"""<name|hostmask> <capability> """<name|hostmask> <capability>
Gives the user specified by <name> (or the user to whom <hostmask> Gives the user specified by <name> (or the user to whom <hostmask>
@ -268,9 +270,9 @@ class Admin(callbacks.Plugin):
irc.replySuccess() irc.replySuccess()
else: else:
irc.error('You can\'t add capabilities you don\'t have.') irc.error('You can\'t add capabilities you don\'t have.')
addcapability = wrap(addcapability, ['otherUser', 'lowered']) add = wrap(add, ['otherUser', 'lowered'])
def removecapability(self, irc, msg, args, user, capability): def remove(self, irc, msg, args, user, capability):
"""<name|hostmask> <capability> """<name|hostmask> <capability>
Takes from the user specified by <name> (or the user to whom Takes from the user specified by <name> (or the user to whom
@ -287,7 +289,7 @@ class Admin(callbacks.Plugin):
else: else:
s = 'You can\'t remove capabilities you don\'t have.' s = 'You can\'t remove capabilities you don\'t have.'
irc.error(s) irc.error(s)
removecapability = wrap(removecapability, ['otherUser','lowered']) remove = wrap(remove, ['otherUser','lowered'])
def ignore(self, irc, msg, args, hostmask, expires): def ignore(self, irc, msg, args, hostmask, expires):
"""<hostmask|nick> [<expires>] """<hostmask|nick> [<expires>]

View File

@ -61,16 +61,27 @@ class AdminTestCase(PluginTestCase):
self.assertNotError('admin ignore foo!bar@baz') self.assertNotError('admin ignore foo!bar@baz')
self.assertNotError('admin ignores') self.assertNotError('admin ignores')
def testAddcapability(self): def testCapabilityAdd(self):
self.assertError('addcapability sdlkfj foo') self.assertError('capability add foo bar')
u = ircdb.users.newUser() u = ircdb.users.newUser()
u.name = 'foo' u.name = 'foo'
ircdb.users.setUser(u) ircdb.users.setUser(u)
self.assertError('removecapability foo bar') self.assertNotError('capability add foo bar')
self.assertNotRegexp('removecapability foo bar', 'find') self.assertError('addcapability foo baz')
self.assert_('bar' in u.capabilities)
ircdb.users.delUser(u.id)
def testRemoveCapability(self): def testCapabilityRemove(self):
self.assertError('removecapability alsdfkjasd foo') self.assertError('capability remove foo bar')
u = ircdb.users.newUser()
u.name = 'foo'
ircdb.users.setUser(u)
self.assertNotError('capability add foo bar')
self.assert_('bar' in u.capabilities)
self.assertError('removecapability foo bar')
self.assertNotError('capability remove foo bar')
self.assert_(not 'bar' in u.capabilities)
ircdb.users.delUser(u.id)
def testJoin(self): def testJoin(self):
m = self.getMsg('join #foo') m = self.getMsg('join #foo')
@ -110,8 +121,7 @@ class AdminTestCase(PluginTestCase):
conf.supybot.nick.setValue(original) conf.supybot.nick.setValue(original)
def testAddCapabilityOwner(self): def testAddCapabilityOwner(self):
self.assertError('admin addcapability %s owner' % self.nick) self.assertError('admin capability add %s owner' % self.nick)
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: