3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-26 12:43:09 +01:00
PyLink/tests/test_relay.py

41 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 utils
import classes
import relay
def dummyf():
pass
class TestRelay(unittest.TestCase):
def setUp(self):
self.irc = classes.FakeIRC('unittest', classes.FakeProto(), classes.testconf)
self.irc.maxnicklen = 20
self.irc.proto.__name__ = "test"
self.f = relay.normalizeNick
def testNormalizeNick(self):
2015-07-18 07:52:55 +02:00
# Second argument simply states the suffix.
self.assertEqual(self.f(self.irc, 'unittest', 'helloworld'), 'helloworld/unittest')
self.assertEqual(self.f(self.irc, 'unittest', 'ObnoxiouslyLongNick'), 'Obnoxiously/unittest')
self.assertEqual(self.f(self.irc, 'unittest', '10XAAAAAA'), '_10XAAAAAA/unittest')
def testNormalizeNickConflict(self):
2015-07-18 07:52:55 +02:00
self.assertEqual(self.f(self.irc, 'unittest', 'helloworld'), 'helloworld/unittest')
self.irc.users['10XAAAAAA'] = classes.IrcUser('helloworld/unittest', 1234, '10XAAAAAA')
# Increase amount of /'s by one
2015-07-18 07:52:55 +02:00
self.assertEqual(self.f(self.irc, 'unittest', '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.
2015-07-18 07:52:55 +02:00
self.assertEqual(self.f(self.irc, 'unittest', 'helloworld'), 'helloworl///unittest')
def testNormalizeNickRemovesSlashes(self):
self.irc.proto.__name__ = "charybdis"
2015-07-18 07:52:55 +02:00
self.assertEqual(self.f(self.irc, 'unittest', 'helloworld'), 'helloworld|unittest')
self.assertEqual(self.f(self.irc, 'unittest', 'abcde/eJanus'), 'abcde|eJanu|unittest')
self.assertEqual(self.f(self.irc, 'unittest', 'ObnoxiouslyLongNick'), 'Obnoxiously|unittest')