use check_auth in banreview, and made a workaround so testcases still pass

This commit is contained in:
Elián Hanisch
2010-04-04 01:31:15 -03:00
parent b6887f5ede
commit 484d45e705
2 changed files with 27 additions and 6 deletions

View File

@ -1103,8 +1103,11 @@ class Bantracker(callbacks.Plugin):
irc.reply("%s/bans.cgi?log=%s&mark=%s" % (self.registryValue('bansite'), id, highlight), private=True)
banlink = wrap(banlink, ['id', optional('somethingWithoutSpaces')])
def banReview(self, irc, msg, args):
"""Lists pending ban reviews."""
def banreview(self, irc, msg, args):
"""
Lists pending ban reviews."""
if not self.check_auth(irc, msg, args):
return
count = {}
for reviews in self.pendingReviews.itervalues():
for nick, msg in reviews:
@ -1117,6 +1120,6 @@ class Bantracker(callbacks.Plugin):
s = 'Pending ban reviews (%s): %s' %(total, s)
irc.reply(s)
banreview = wrap(banReview)
banreview = wrap(banreview)
Class = Bantracker

View File

@ -2,6 +2,7 @@ from supybot.test import *
import supybot.conf as conf
import supybot.ircmsgs as ircmsgs
import supybot.world as world
import time
@ -20,11 +21,22 @@ class BantrackerTestCase(ChannelPluginTestCase):
def setUp(self):
super(BantrackerTestCase, self).setUp()
self.setDb()
pluginConf.request.setValue(False) # disable comments
pluginConf.request.ignore.set('')
pluginConf.request.forward.set('')
pluginConf.request.review.setValue(1.0/86400) # one second
self.setDb()
# Bantracker for some reason doesn't use Supybot's own methods for check capabilities,
# so it doesn't have a clue about testing and screws my tests by default.
# This would fix it until I bring myself to take a look
cb = self.getCallback()
f = cb.check_auth
def test_check_auth(*args, **kwargs):
if world.testing:
return True
else:
return f(*args, **kwargs)
cb.check_auth = test_check_auth
def setDb(self):
import sqlite, os
@ -233,8 +245,7 @@ class BantrackerTestCase(ChannelPluginTestCase):
msg2 = ircmsgs.privmsg('nick', 'Hello World')
msg3 = ircmsgs.notice('#chan', 'Hello World')
msg4 = ircmsgs.privmsg('nick_', 'Hello World')
cb = self.getCallback()
pr = cb.pendingReviews
pr = self.getCallback().pendingReviews
pr['host.net'] = [('op', msg1), ('op', msg2), ('op_', msg3)]
pr['home.net'] = [('dude', msg4)]
self.assertResponse('banreview', 'Pending ban reviews (4): op_:1 dude:1 op:2')
@ -249,6 +260,13 @@ class BantrackerTestCase(ChannelPluginTestCase):
items = pr['home.net']
self.assertTrue(items[0][0] == 'dude' and items[0][1] == msg4)
def testReviewBanreview(self):
pr = self.getCallback().pendingReviews
m = ircmsgs.privmsg('#test', 'asd')
pr['host.net'] = [('op', m), ('op_', m), ('op', m)]
pr['home.net'] = [('dude', m)]
self.assertResponse('banreview', 'Pending ban reviews (4): op_:1 dude:1 op:2')
def testBan(self):
self.feedBan('asd!*@*')
fetch = self.query("SELECT id,channel,mask,operator FROM bans")