comparison src/test/test_core_xmpp.py @ 780:9810f22ba733

test: store the constants in constants.py + better PEP8 compliance
author souliane <souliane@mailoo.org>
date Sat, 04 Jan 2014 15:45:08 +0100
parents e20c823f23e2
children 2136be5a44a8
comparison
equal deleted inserted replaced
779:a978c703bf57 780:9810f22ba733
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.test import helpers 20 from sat.test import helpers
21 from constants import Const
21 from twisted.trial import unittest 22 from twisted.trial import unittest
22 from sat.core.sat_main import SAT 23 from sat.core.sat_main import SAT
23 from sat.core import xmpp 24 from sat.core import xmpp
24 from twisted.internet import defer 25 from twisted.internet import defer
25 from twisted.words.protocols.jabber.jid import JID 26 from twisted.words.protocols.jabber.jid import JID
65 self.host = helpers.FakeSAT() 66 self.host = helpers.FakeSAT()
66 self.roster = xmpp.SatRosterProtocol(self.host) 67 self.roster = xmpp.SatRosterProtocol(self.host)
67 self.roster.parent = helpers.FakeClient(self.host) 68 self.roster.parent = helpers.FakeClient(self.host)
68 69
69 def test_onRosterSet(self): 70 def test_onRosterSet(self):
70 roster_item = RosterItem(helpers.TEST_JID) 71 roster_item = RosterItem(Const.TEST_JID)
71 roster_item.name = u"Test Man" 72 roster_item.name = u"Test Man"
72 roster_item.subscriptionTo = True 73 roster_item.subscriptionTo = True
73 roster_item.subscriptionFrom = True 74 roster_item.subscriptionFrom = True
74 roster_item.ask = False 75 roster_item.ask = False
75 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"])
76 self.host.bridge.expectCall("newContact", helpers.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.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.roster.onRosterSet(roster_item) 78 self.roster.onRosterSet(roster_item)
78 79
79 80
80 class SatPresenceProtocolTest(unittest.TestCase): 81 class SatPresenceProtocolTest(unittest.TestCase):
81 82
83 self.host = helpers.FakeSAT() 84 self.host = helpers.FakeSAT()
84 self.presence = xmpp.SatPresenceProtocol(self.host) 85 self.presence = xmpp.SatPresenceProtocol(self.host)
85 self.presence.parent = helpers.FakeClient(self.host) 86 self.presence.parent = helpers.FakeClient(self.host)
86 87
87 def test_availableReceived(self): 88 def test_availableReceived(self):
88 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr': 'statut de test'}, helpers.TEST_PROFILE) 89 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {'default': "test status", 'fr': 'statut de test'}, Const.TEST_PROFILE)
89 self.presence.availableReceived(helpers.TEST_JID, 'xa', {None: "test status", 'fr': 'statut de test'}, 15) 90 self.presence.availableReceived(Const.TEST_JID, 'xa', {None: "test status", 'fr': 'statut de test'}, 15)
90 91
91 def test_availableReceived_empty_statuses(self): 92 def test_availableReceived_empty_statuses(self):
92 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "xa", 15, {}, helpers.TEST_PROFILE) 93 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "xa", 15, {}, Const.TEST_PROFILE)
93 self.presence.availableReceived(helpers.TEST_JID, 'xa', None, 15) 94 self.presence.availableReceived(Const.TEST_JID, 'xa', None, 15)
94 95
95 def test_unavailableReceived(self): 96 def test_unavailableReceived(self):
96 self.host.bridge.expectCall("presenceUpdate", helpers.TEST_JID_STR, "unavailable", 0, {}, helpers.TEST_PROFILE) 97 self.host.bridge.expectCall("presenceUpdate", Const.TEST_JID_STR, "unavailable", 0, {}, Const.TEST_PROFILE)
97 self.presence.unavailableReceived(helpers.TEST_JID, None) 98 self.presence.unavailableReceived(Const.TEST_JID, None)
98 99
99 def test_subscribedReceived(self): 100 def test_subscribedReceived(self):
100 self.host.bridge.expectCall("subscribe", "subscribed", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) 101 self.host.bridge.expectCall("subscribe", "subscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
101 self.presence.subscribedReceived(helpers.TEST_JID) 102 self.presence.subscribedReceived(Const.TEST_JID)
102 103
103 def test_unsubscribedReceived(self): 104 def test_unsubscribedReceived(self):
104 self.host.bridge.expectCall("subscribe", "unsubscribed", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) 105 self.host.bridge.expectCall("subscribe", "unsubscribed", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
105 self.presence.unsubscribedReceived(helpers.TEST_JID) 106 self.presence.unsubscribedReceived(Const.TEST_JID)
106 107
107 def test_subscribeReceived(self): 108 def test_subscribeReceived(self):
108 self.host.bridge.expectCall("subscribe", "subscribe", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) 109 self.host.bridge.expectCall("subscribe", "subscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
109 self.presence.subscribeReceived(helpers.TEST_JID) 110 self.presence.subscribeReceived(Const.TEST_JID)
110 111
111 def test_unsubscribeReceived(self): 112 def test_unsubscribeReceived(self):
112 self.host.bridge.expectCall("subscribe", "unsubscribe", helpers.TEST_JID.userhost(), helpers.TEST_PROFILE) 113 self.host.bridge.expectCall("subscribe", "unsubscribe", Const.TEST_JID.userhost(), Const.TEST_PROFILE)
113 self.presence.unsubscribeReceived(helpers.TEST_JID) 114 self.presence.unsubscribeReceived(Const.TEST_JID)