Fixed test and the names of some configuration variables.

This commit is contained in:
Jeremy Fincher 2004-01-31 21:56:39 +00:00
parent f3fd7dabe1
commit 2b93f028d9
2 changed files with 62 additions and 42 deletions

View File

@ -57,13 +57,13 @@ conf.registerPlugin('Karma')
conf.registerChannelValue(conf.supybot.plugins.Karma, 'simpleOutput',
registry.Boolean(False, """Determines whether the bot will output shorter
versions of the karma output when requesting a single thing's karma."""))
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaResponse',
conf.registerChannelValue(conf.supybot.plugins.Karma, 'response',
registry.Boolean(False, """Determines whether the bot will reply with a
success message when something's karma is incrneased or decreased."""))
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaRankingDisplay',
conf.registerChannelValue(conf.supybot.plugins.Karma, 'rankingDisplay',
registry.Integer(3, """Determines how many highest/lowest karma things are
shown when karma is called with no arguments."""))
conf.registerChannelValue(conf.supybot.plugins.Karma, 'karmaMostDisplay',
conf.registerChannelValue(conf.supybot.plugins.Karma, 'mostDisplay',
registry.Integer(25, """Determines how many karma things are shown when
the most command is called.'"""))
@ -154,7 +154,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
irc.reply('I didn\'t know the karma for any '
'of those things.')
else: # No name was given. Return the top/bottom N karmas.
limit = self.registryValue('karmaRankingDisplay', channel)
limit = self.registryValue('rankingDisplay', channel)
cursor.execute("""SELECT name, added-subtracted
FROM karma
ORDER BY added-subtracted DESC
@ -192,7 +192,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
orderby = 'added+subtracted'
sql = "SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s" % \
(orderby, orderby,
self.registryValue('karmaMostDisplay', channel))
self.registryValue('mostDisplay', channel))
db = self.getDb(channel)
cursor = db.cursor()
cursor.execute(sql)
@ -215,7 +215,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
cursor.execute("""UPDATE karma
SET added=added+1
WHERE normalized=%s""", normalized)
if self.registryValue('karmaResponse', msg.args[0]):
if self.registryValue('response', msg.args[0]):
irc.replySuccess()
def decreaseKarma(self, irc, msg, match):
@ -229,7 +229,7 @@ class Karma(callbacks.PrivmsgCommandAndRegexp, plugins.ChannelDBHandler):
cursor.execute("""UPDATE karma
SET subtracted=subtracted+1
WHERE normalized=%s""", normalized)
if self.registryValue('karmaResponse', msg.args[0]):
if self.registryValue('response', msg.args[0]):
irc.replySuccess()

View File

@ -69,30 +69,37 @@ if sqlite is not None:
'Karma for \'MoO\'.*increased 1.*total.*1')
def testKarmaRankingDisplayConfigurable(self):
self.assertNotError('karma config karma-response on')
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('bar++')
self.assertNotError('bar++')
self.assertNotError('bar++')
self.assertNotError('baz++')
self.assertNotError('baz++')
self.assertNotError('quux++')
self.assertNotError('xuuq--')
self.assertNotError('zab--')
self.assertNotError('zab--')
self.assertNotError('rab--')
self.assertNotError('rab--')
self.assertNotError('rab--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertRegexp('karma', 'foo.*bar.*baz.*oof.*rab.*zab')
self.assertNotError('karma config karma-ranking-display 4')
self.assertRegexp('karma', 'foo.*bar.*baz.*quux')
try:
orig = conf.supybot.plugins.Karma.response()
conf.supybot.plugins.Karma.response.setValue(True)
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('foo++')
self.assertNotError('bar++')
self.assertNotError('bar++')
self.assertNotError('bar++')
self.assertNotError('baz++')
self.assertNotError('baz++')
self.assertNotError('quux++')
self.assertNotError('xuuq--')
self.assertNotError('zab--')
self.assertNotError('zab--')
self.assertNotError('rab--')
self.assertNotError('rab--')
self.assertNotError('rab--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertNotError('oof--')
self.assertRegexp('karma', 'foo.*bar.*baz.*oof.*rab.*zab')
original = conf.supybot.plugins.Karma.rankingDisplay()
conf.supybot.plugins.Karma.rankingDisplay.setValue(4)
self.assertRegexp('karma', 'foo.*bar.*baz.*quux')
finally:
conf.supybot.plugins.Karma.response.setValue(orig)
conf.supybot.plugins.Karma.rankingDisplay.setValue(original)
def testMost(self):
self.assertError('most increased')
@ -116,16 +123,24 @@ if sqlite is not None:
self.assertRegexp('karma most decreased', 'foo.*bar')
def testSimpleOutput(self):
self.assertNotError('karma config simple-output on')
self.assertNoResponse('foo++', 2)
self.assertResponse('karma foo', 'foo: 1')
self.assertNoResponse('bar--', 2)
self.assertResponse('karma bar', 'bar: -1')
try:
orig = conf.supybot.plugins.Karma.simpleOutput()
conf.supybot.plugins.Karma.simpleOutput.setValue(True)
self.assertNoResponse('foo++', 2)
self.assertResponse('karma foo', 'foo: 1')
self.assertNoResponse('bar--', 2)
self.assertResponse('karma bar', 'bar: -1')
finally:
conf.supybot.plugins.Karma.simpleOutput.setValue(orig)
def testKarmaOutputConfigurable(self):
self.assertNoResponse('foo++', 2)
self.assertNotError('karma config karma-response on')
self.assertNotError('foo++')
try:
orig = conf.supybot.plugins.Karma.response()
conf.supybot.plugins.Karma.response.setValue(True)
self.assertNotError('foo++')
finally:
conf.supybot.plugins.Karma.response.setValue(orig)
def testKarmaMostDisplayConfigurable(self):
self.assertNoResponse('foo++', 1)
@ -137,10 +152,15 @@ if sqlite is not None:
self.assertNoResponse('foo--', 1)
self.assertNoResponse('foo--', 1)
self.assertNoResponse('foo--', 1)
self.assertNotError('karma config karma-most-display 1')
self.assertRegexp('karma most active', '(?!bar)')
self.assertNotError('karma config karma-most-display 25')
self.assertRegexp('karma most active', 'bar')
try:
orig = conf.supybot.plugins.Karma.mostDisplay()
conf.supybot.plugins.Karma.mostDisplay.setValue(1)
self.assertRegexp('karma most active', '(?!bar)')
conf.supybot.plugins.Karma.mostDisplay.setValue(25)
self.assertRegexp('karma most active', 'bar')
finally:
conf.supybot.plugins.Karma.mostDisplay.setValue(orig)
def testIncreaseKarmaWithNickNotCallingInvalidCommand(self):
self.assertNoResponse('%s: foo++' % self.irc.nick, 3)