Initial import to Tizen
[profile/ivi/python-twisted.git] / twisted / words / test / test_ircsupport.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.words.im.ircsupport}.
6 """
7
8 from twisted.trial.unittest import TestCase
9 from twisted.test.proto_helpers import StringTransport
10
11 from twisted.words.im.basechat import Conversation, ChatUI
12 from twisted.words.im.ircsupport import IRCAccount, IRCProto
13
14
15
16 class StubConversation(Conversation):
17     def show(self):
18         pass
19
20
21
22 class StubChatUI(ChatUI):
23     def getGroupConversation(self, group, Class=StubConversation, stayHidden=0):
24         return ChatUI.getGroupConversation(self, group, Class, stayHidden)
25
26
27
28 class IRCProtoTests(TestCase):
29     """
30     Tests for L{IRCProto}.
31     """
32     def setUp(self):
33         self.account = IRCAccount(
34             "Some account", False, "alice", None, "example.com", 6667)
35         self.proto = IRCProto(self.account, StubChatUI(), None)
36
37
38     def test_login(self):
39         """
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.
42         """
43         transport = StringTransport()
44         self.proto.makeConnection(transport)
45         self.assertEqual(
46             transport.value(),
47             "NICK alice\r\n"
48             "USER alice foo bar :Twisted-IM user\r\n")
49
50
51     def test_authenticate(self):
52         """
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.
55         """
56         self.account.password = "secret"
57         transport = StringTransport()
58         self.proto.makeConnection(transport)
59         self.assertEqual(
60             transport.value(),
61             "PASS :secret\r\n"
62             "NICK alice\r\n"
63             "USER alice foo bar :Twisted-IM user\r\n")
64
65
66     def test_channels(self):
67         """
68         If created with an account with a list of channels, L{IRCProto}
69         joins each of those channels after registering.
70         """
71         self.account.channels = ['#foo', '#bar']
72         transport = StringTransport()
73         self.proto.makeConnection(transport)
74         self.assertEqual(
75             transport.value(),
76             "NICK alice\r\n"
77             "USER alice foo bar :Twisted-IM user\r\n"
78             "JOIN #foo\r\n"
79             "JOIN #bar\r\n")