Imported Upstream version 12.1.0
[contrib/python-twisted.git] / twisted / words / test / test_basechat.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.words.im.basechat}.
6 """
7
8 from twisted.trial import unittest
9 from twisted.words.im import basechat, basesupport
10
11
12 class ChatUITests(unittest.TestCase):
13     """
14     Tests for the L{basechat.ChatUI} chat client.
15     """
16     def setUp(self):
17         self.ui = basechat.ChatUI()
18         self.account = basesupport.AbstractAccount("fooAccount", False, "foo",
19                                                    "password", "host", "port")
20         self.person = basesupport.AbstractPerson("foo", self.account)
21
22
23     def test_contactChangedNickNoKey(self):
24         """
25         L{basechat.ChatUI.contactChangedNick} on an
26         L{twisted.words.im.interfaces.IPerson} who doesn't have an account
27         associated with the L{basechat.ChatUI} instance has no effect.
28         """
29         self.assertEqual(self.person.name, "foo")
30         self.assertEqual(self.person.account, self.account)
31
32         self.ui.contactChangedNick(self.person, "bar")
33         self.assertEqual(self.person.name, "foo")
34         self.assertEqual(self.person.account, self.account)
35
36
37     def test_contactChangedNickNoConversation(self):
38         """
39         L{basechat.ChatUI.contactChangedNick} changes the name for an
40         L{twisted.words.im.interfaces.IPerson}.
41         """
42         self.ui.persons[self.person.name, self.person.account] = self.person
43
44         self.assertEqual(self.person.name, "foo")
45         self.assertEqual(self.person.account, self.account)
46
47         self.ui.contactChangedNick(self.person, "bar")
48         self.assertEqual(self.person.name, "bar")
49         self.assertEqual(self.person.account, self.account)
50
51
52     def test_contactChangedNickHasConversation(self):
53         """
54         If an L{twisted.words.im.interfaces.IPerson} is in a
55         L{basechat.Conversation}, L{basechat.ChatUI.contactChangedNick} causes a
56         name change for that person in both the L{basechat.Conversation} and the
57         L{basechat.ChatUI}.
58         """
59         self.ui.persons[self.person.name, self.person.account] = self.person
60         conversation = basechat.Conversation(self.person, self.ui)
61         self.ui.conversations[self.person] = conversation
62
63         self.assertEqual(self.person.name, "foo")
64         self.assertEqual(self.person.account, self.account)
65
66         self.ui.contactChangedNick(self.person, "bar")
67         self.assertEqual(self.person.name, "bar")
68         self.assertEqual(self.person.account, self.account)