1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for L{twisted.words.im.ircsupport}.
8 from twisted.trial.unittest import TestCase
9 from twisted.test.proto_helpers import StringTransport
11 from twisted.words.im.basechat import Conversation, ChatUI
12 from twisted.words.im.ircsupport import IRCAccount, IRCProto
16 class StubConversation(Conversation):
22 class StubChatUI(ChatUI):
23 def getGroupConversation(self, group, Class=StubConversation, stayHidden=0):
24 return ChatUI.getGroupConversation(self, group, Class, stayHidden)
28 class IRCProtoTests(TestCase):
30 Tests for L{IRCProto}.
33 self.account = IRCAccount(
34 "Some account", False, "alice", None, "example.com", 6667)
35 self.proto = IRCProto(self.account, StubChatUI(), None)
40 When L{IRCProto} is connected to a transport, it sends I{NICK} and
41 I{USER} commands with the username from the account object.
43 transport = StringTransport()
44 self.proto.makeConnection(transport)
48 "USER alice foo bar :Twisted-IM user\r\n")
51 def test_authenticate(self):
53 If created with an account with a password, L{IRCProto} sends a
54 I{PASS} command before the I{NICK} and I{USER} commands.
56 self.account.password = "secret"
57 transport = StringTransport()
58 self.proto.makeConnection(transport)
63 "USER alice foo bar :Twisted-IM user\r\n")
66 def test_channels(self):
68 If created with an account with a list of channels, L{IRCProto}
69 joins each of those channels after registering.
71 self.account.channels = ['#foo', '#bar']
72 transport = StringTransport()
73 self.proto.makeConnection(transport)
77 "USER alice foo bar :Twisted-IM user\r\n"