mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
Added more tests.
This commit is contained in:
parent
02ba0176b2
commit
ec2908bc6c
@ -50,6 +50,12 @@ class IrcUserTestCase(unittest.TestCase):
|
||||
self.failIf(u.checkCapability('!bar'))
|
||||
self.failIf(u.checkCapability('foo'))
|
||||
|
||||
def testOwner(self):
|
||||
u = ircdb.IrcUser()
|
||||
u.addCapability('owner')
|
||||
self.failUnless(u.checkCapability('foo'))
|
||||
self.failIf(u.checkCapability('!foo'))
|
||||
|
||||
def testInitCapabilities(self):
|
||||
u = ircdb.IrcUser(capabilities=['foo'])
|
||||
self.failUnless(u.checkCapability('foo'))
|
||||
@ -103,8 +109,10 @@ class IrcChannelTestCase(unittest.TestCase):
|
||||
c = ircdb.IrcChannel()
|
||||
c.setDefaultCapability(False)
|
||||
self.failIf(c.checkCapability('foo'))
|
||||
self.failUnless(c.checkCapability('!foo'))
|
||||
c.setDefaultCapability(True)
|
||||
self.failUnless(c.checkCapability('foo'))
|
||||
self.failIf(c.checkCapability('!foo'))
|
||||
|
||||
def testLobotomized(self):
|
||||
c = ircdb.IrcChannel(lobotomized=True)
|
||||
@ -124,8 +132,18 @@ class IrcChannelTestCase(unittest.TestCase):
|
||||
c.removeBan(banmask)
|
||||
self.failIf(c.checkIgnored(prefix))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class FunctionsTestCase(unittest.TestCase):
|
||||
def testIsAntiCapability(self):
|
||||
self.failIf(ircdb.isAntiCapability('foo'))
|
||||
self.failIf(ircdb.isAntiCapability('#foo.bar'))
|
||||
self.failUnless(ircdb.isAntiCapability('!foo'))
|
||||
self.failUnless(ircdb.isAntiCapability('#foo.!bar'))
|
||||
|
||||
def testIsChannelCapability(self):
|
||||
self.failIf(ircdb.isChannelCapability('foo'))
|
||||
self.failUnless(ircdb.isChannelCapability('#foo.bar'))
|
||||
|
||||
def testMakeAntiCapability(self):
|
||||
self.assertEqual(ircdb.makeAntiCapability('foo'), '!foo')
|
||||
self.assertEqual(ircdb.makeAntiCapability('#foo.bar'), '#foo.!bar')
|
||||
|
@ -189,3 +189,25 @@ class IrcCallbackTestCase(unittest.TestCase):
|
||||
commands = map(makeCommand, msgs)
|
||||
self.assertEqual(doCommandCatcher.L,
|
||||
list(flatten(zip(commands, commands))))
|
||||
|
||||
def testFirstCommands(self):
|
||||
oldconfthrottle = conf.throttleTime
|
||||
conf.throttleTime = 0
|
||||
nick = 'nick'
|
||||
user = 'user any user'
|
||||
password = 'password'
|
||||
expected = [ircmsgs.nick(nick), ircmsgs.user(nick, user)]
|
||||
irc = irclib.Irc(nick, user)
|
||||
msgs = [irc.takeMsg()]
|
||||
while msgs[-1] != None:
|
||||
msgs.append(irc.takeMsg())
|
||||
msgs.pop()
|
||||
self.assertEqual(msgs, expected)
|
||||
irc = irclib.Irc(nick, user, password=password)
|
||||
msgs = [irc.takeMsg()]
|
||||
while msgs[-1] != None:
|
||||
msgs.append(irc.takeMsg())
|
||||
msgs.pop()
|
||||
expected.insert(0, ircmsgs.password(password))
|
||||
self.assertEqual(msgs, expected)
|
||||
conf.throttleTime = oldconfthrottle
|
||||
|
@ -35,6 +35,7 @@ import copy
|
||||
import pickle
|
||||
|
||||
import ircmsgs
|
||||
import ircutils
|
||||
|
||||
|
||||
class IrcMsgTestCase(unittest.TestCase):
|
||||
@ -95,6 +96,7 @@ class IrcMsgTestCase(unittest.TestCase):
|
||||
self.assertEqual(msg, pickle.loads(pickle.dumps(msg)))
|
||||
self.assertEqual(msg, copy.copy(msg))
|
||||
|
||||
class FunctionsTestCase(unittest.TestCase):
|
||||
def testIsAction(self):
|
||||
L = [':jemfinch!~jfincher@ts26-2.homenet.ohio-state.edu PRIVMSG'
|
||||
' #sourcereview :ACTION does something',
|
||||
@ -112,3 +114,26 @@ class IrcMsgTestCase(unittest.TestCase):
|
||||
s = 'foo bar baz'
|
||||
msg = ircmsgs.action('#foo', s)
|
||||
self.assertEqual(ircmsgs.unAction(msg), s)
|
||||
|
||||
def testBan(self):
|
||||
channel = '#osu'
|
||||
ban = '*!*@*.edu'
|
||||
exception = '*!*@*ohio-state.edu'
|
||||
noException = ircmsgs.ban(channel, ban)
|
||||
self.assertEqual(ircutils.separateModes(noException.args[1:]),
|
||||
[('+b', ban)])
|
||||
withException = ircmsgs.ban(channel, ban, exception)
|
||||
self.assertEqual(ircutils.separateModes(withException.args[1:]),
|
||||
[('+b', ban), ('+e', exception)])
|
||||
|
||||
def testBans(self):
|
||||
channel = '#osu'
|
||||
bans = ['*!*@*', 'jemfinch!*@*']
|
||||
exceptions = ['*!*@*ohio-state.edu']
|
||||
noException = ircmsgs.bans(channel, bans)
|
||||
self.assertEqual(ircutils.separateModes(noException.args[1:]),
|
||||
[('+b', bans[0]), ('+b', bans[1])])
|
||||
withExceptions = ircmsgs.bans(channel, bans, exceptions)
|
||||
self.assertEqual(ircutils.separateModes(withExceptions.args[1:]),
|
||||
[('+b', bans[0]), ('+b', bans[1]),
|
||||
('+e', exceptions[0])])
|
||||
|
@ -60,6 +60,9 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.failUnless(ircutils.isChannel('&foo'))
|
||||
self.failUnless(ircutils.isChannel('+foo'))
|
||||
self.failUnless(ircutils.isChannel('!foo'))
|
||||
self.failIf(ircutils.isChannel('#foo bar'))
|
||||
self.failIf(ircutils.isChannel('#foo,bar'))
|
||||
self.failIf(ircutils.isChannel('#foobar\x07'))
|
||||
self.failIf(ircutils.isChannel('foo'))
|
||||
self.failIf(ircutils.isChannel(''))
|
||||
|
||||
@ -79,8 +82,11 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
self.failUnless(ircutils.isIP('100.100.100.100'))
|
||||
|
||||
def banmask(self):
|
||||
self.failUnless(ircutils.hostmaskPatternEqual(\
|
||||
ircutils.banmask(self.hostmask), self.hostmask))
|
||||
for msg in msgs:
|
||||
if ircutils.isUserHostmask(msg.prefix):
|
||||
self.failUnless(ircutils.hostmaskPatternEqual
|
||||
(ircutils.banmask(msg.prefix),
|
||||
msg.prefix))
|
||||
|
||||
def testSeparateModes(self):
|
||||
self.assertEqual(ircutils.separateModes(['+ooo', 'x', 'y', 'z']),
|
||||
@ -109,3 +115,11 @@ class FunctionsTestCase(unittest.TestCase):
|
||||
private = ircmsgs.privmsg('jemfinch', 'bar baz', prefix=prefix)
|
||||
self.assertEqual(ircutils.replyTo(channel), channel.args[0])
|
||||
self.assertEqual(ircutils.replyTo(private), private.nick)
|
||||
|
||||
def testJoinModes(self):
|
||||
plusE = ('+e', '*!*@*ohio-state.edu')
|
||||
plusB = ('+b', '*!*@*umich.edu')
|
||||
minusL = ('-l', None)
|
||||
modes = [plusB, plusE, minusL]
|
||||
self.assertEqual(ircutils.joinModes(modes),
|
||||
['+be-l', plusB[1], plusE[1]])
|
||||
|
Loading…
Reference in New Issue
Block a user