3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00
PyLink/tests/test_relay.py

46 lines
1.8 KiB
Python
Raw Normal View History

import sys
import os
cwd = os.getcwd()
sys.path += [cwd, os.path.join(cwd, 'plugins')]
import unittest
import classes
import relay
def dummyf():
pass
class TestRelay(unittest.TestCase):
def setUp(self):
2015-09-07 08:39:10 +02:00
self.irc = classes.FakeIRC('fakeirc', classes.FakeProto)
self.irc.maxnicklen = 20
self.f = lambda nick: relay.normalizeNick(self.irc, 'unittest', nick)
# Fake our protocol name to something that supports slashes in nicks.
# relay uses a whitelist for this to prevent accidentally introducing
# bad nicks:
2015-09-07 08:39:10 +02:00
self.irc.protoname = "inspircd"
def testNormalizeNick(self):
2015-07-18 07:52:55 +02:00
# Second argument simply states the suffix.
self.assertEqual(self.f('helloworld'), 'helloworld/unittest')
self.assertEqual(self.f('ObnoxiouslyLongNick'), 'Obnoxiously/unittest')
self.assertEqual(self.f('10XAAAAAA'), '_10XAAAAAA/unittest')
def testNormalizeNickConflict(self):
self.assertEqual(self.f('helloworld'), 'helloworld/unittest')
self.irc.users['10XAAAAAA'] = classes.IrcUser('helloworld/unittest', 1234, '10XAAAAAA')
# Increase amount of /'s by one
self.assertEqual(self.f('helloworld'), 'helloworld//unittest')
self.irc.users['10XAAAAAB'] = classes.IrcUser('helloworld//unittest', 1234, '10XAAAAAB')
# Cut off the nick, not the suffix if the result is too long.
self.assertEqual(self.f('helloworld'), 'helloworl///unittest')
def testNormalizeNickRemovesSlashes(self):
2015-09-07 08:39:10 +02:00
self.irc.protoname = "charybdis"
try:
self.assertEqual(self.f('helloworld'), 'helloworld|unittest')
self.assertEqual(self.f('abcde/eJanus'), 'abcde|eJanu|unittest')
self.assertEqual(self.f('ObnoxiouslyLongNick'), 'Obnoxiously|unittest')
finally:
2015-09-07 08:39:10 +02:00
self.irc.protoname = "inspircd"