comparison src/test/test_core_xmpp.py @ 792:2136be5a44a8

test: define the constants JIDs and profiles as lists
author souliane <souliane@mailoo.org>
date Thu, 09 Jan 2014 11:18:33 +0100
parents 9810f22ba733
children 1fe00f0c9a91
comparison
equal deleted inserted replaced
791:23b0c949b86c 792:2136be5a44a8
30 30
31 class SatXMPPClientTest(unittest.TestCase): 31 class SatXMPPClientTest(unittest.TestCase):
32 32
33 def setUp(self): 33 def setUp(self):
34 self.host = helpers.FakeSAT() 34 self.host = helpers.FakeSAT()
35 self.client = xmpp.SatXMPPClient(self.host, "test_profile", JID("test@example.org"), "test") 35 self.client = xmpp.SatXMPPClient(self.host, Const.PROFILE[0], JID("test@example.org"), "test")
36 36
37 def test_init(self): 37 def test_init(self):
38 """Check that init values are correctly initialised""" 38 """Check that init values are correctly initialised"""
39 self.assertEqual(self.client.profile, "test_profile") 39 self.assertEqual(self.client.profile, Const.PROFILE[0])
40 print self.client.host 40 print self.client.host
41 self.assertEqual(self.client.host_app, self.host) 41 self.assertEqual(self.client.host_app, self.host)
42 self.assertTrue(isinstance(self.client.client_initialized, defer.Deferred)) 42 self.assertTrue(isinstance(self.client.client_initialized, defer.Deferred))
43 43
44 44
54 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1"> 54 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1">
55 <body>test</body> 55 <body>test</body>
56 </message> 56 </message>
57 """ 57 """
58 stanza = parseXml(xml) 58 stanza = parseXml(xml)
59 self.host.bridge.expectCall("newMessage", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile="test_profile") 59 self.host.bridge.expectCall("newMessage", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile=Const.PROFILE[0])
60 self.message.onMessage(stanza) 60 self.message.onMessage(stanza)
61 61
62 62
63 class SatRosterProtocolTest(unittest.TestCase): 63 class SatRosterProtocolTest(unittest.TestCase):
64 64
66 self.host = helpers.FakeSAT() 66 self.host = helpers.FakeSAT()
67 self.roster = xmpp.SatRosterProtocol(self.host) 67 self.roster = xmpp.SatRosterProtocol(self.host)
68 self.roster.parent = helpers.FakeClient(self.host) 68 self.roster.parent = helpers.FakeClient(self.host)
69 69
70 def test_onRosterSet(self): 70 def test_onRosterSet(self):
71 roster_item = RosterItem(Const.TEST_JID) 71 roster_item = RosterItem(Const.JID[0])
72 roster_item.name = u"Test Man" 72 roster_item.name = u"Test Man"
73 roster_item.subscriptionTo = True 73 roster_item.subscriptionTo = True
74 roster_item.subscriptionFrom = True 74 roster_item.subscriptionFrom = True
75 roster_item.ask = False 75 roster_item.ask = False
76 roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]) 76 roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"])
77 self.host.bridge.expectCall("newContact", Const.TEST_JID_STR, {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), "test_profile") 77 self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': u'Test Man'}, set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]), Const.PROFILE[0])
78 self.roster.onRosterSet(roster_item) 78 self.roster.onRosterSet(roster_item)
79 79
80 80
81 class SatPresenceProtocolTest(unittest.TestCase): 81 class SatPresenceProtocolTest(unittest.TestCase):
82 82
84 self.host = helpers.FakeSAT() 84 self.host = helpers.FakeSAT()
85 self.presence = xmpp.SatPresenceProtocol(self.host) 85 self.presence = xmpp.SatPresenceProtocol(self.host)
86 self.presence.parent = helpers.FakeClient(self.host) 86 self.presence.parent = helpers.FakeClient(self.host)
87 87
88 def test_availableReceived(self): 88 def test_availableReceived(self):
89 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.TEST_PROFILE) 89 self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.PROFILE[0])
90 self.presence.availableReceived(Const.TEST_JID, 'xa', {None: "test status", 'fr': 'statut de test'}, 15) 90 self.presence.availableReceived(Const.JID[0], 'xa', {None: "test status", 'fr': 'statut de test'}, 15)
91 91
92 def test_availableReceived_empty_statuses(self): 92 def test_availableReceived_empty_statuses(self):
93 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {}, Const.TEST_PROFILE) 93 self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "xa", 15, {}, Const.PROFILE[0])
94 self.presence.availableReceived(Const.TEST_JID, 'xa', None, 15) 94 self.presence.availableReceived(Const.JID[0], 'xa', None, 15)
95 95
96 def test_unavailableReceived(self): 96 def test_unavailableReceived(self):
97 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "unavailable", 0, {}, Const.TEST_PROFILE) 97 self.host.bridge.expectCall("presenceUpdate", Const.JID_STR[0], "unavailable", 0, {}, Const.PROFILE[0])
98 self.presence.unavailableReceived(Const.TEST_JID, None) 98 self.presence.unavailableReceived(Const.JID[0], None)
99 99
100 def test_subscribedReceived(self): 100 def test_subscribedReceived(self):
101 self.host.bridge.expectCall("subscribe", "subscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE) 101 self.host.bridge.expectCall("subscribe", "subscribed", Const.JID[0].userhost(), Const.PROFILE[0])
102 self.presence.subscribedReceived(Const.TEST_JID) 102 self.presence.subscribedReceived(Const.JID[0])
103 103
104 def test_unsubscribedReceived(self): 104 def test_unsubscribedReceived(self):
105 self.host.bridge.expectCall("subscribe", "unsubscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE) 105 self.host.bridge.expectCall("subscribe", "unsubscribed", Const.JID[0].userhost(), Const.PROFILE[0])
106 self.presence.unsubscribedReceived(Const.TEST_JID) 106 self.presence.unsubscribedReceived(Const.JID[0])
107 107
108 def test_subscribeReceived(self): 108 def test_subscribeReceived(self):
109 self.host.bridge.expectCall("subscribe", "subscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE) 109 self.host.bridge.expectCall("subscribe", "subscribe", Const.JID[0].userhost(), Const.PROFILE[0])
110 self.presence.subscribeReceived(Const.TEST_JID) 110 self.presence.subscribeReceived(Const.JID[0])
111 111
112 def test_unsubscribeReceived(self): 112 def test_unsubscribeReceived(self):
113 self.host.bridge.expectCall("subscribe", "unsubscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE) 113 self.host.bridge.expectCall("subscribe", "unsubscribe", Const.JID[0].userhost(), Const.PROFILE[0])
114 self.presence.unsubscribeReceived(Const.TEST_JID) 114 self.presence.unsubscribeReceived(Const.JID[0])