comparison sat/test/test_core_xmpp.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
1 #!/usr/bin/env python2 1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 # SAT: a jabber client 4 # SAT: a jabber client
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
6 6
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 .constants import Const
22 from twisted.trial import unittest 22 from twisted.trial import unittest
23 from sat.core import xmpp 23 from sat.core import xmpp
24 from twisted.words.protocols.jabber.jid import JID 24 from twisted.words.protocols.jabber.jid import JID
25 from wokkel.generic import parseXml 25 from wokkel.generic import parseXml
26 from wokkel.xmppim import RosterItem 26 from wokkel.xmppim import RosterItem
33 self.client = xmpp.SatXMPPClient(self.host, Const.PROFILE[0], JID("test@example.org"), "test") 33 self.client = xmpp.SatXMPPClient(self.host, Const.PROFILE[0], JID("test@example.org"), "test")
34 34
35 def test_init(self): 35 def test_init(self):
36 """Check that init values are correctly initialised""" 36 """Check that init values are correctly initialised"""
37 self.assertEqual(self.client.profile, Const.PROFILE[0]) 37 self.assertEqual(self.client.profile, Const.PROFILE[0])
38 print self.client.host 38 print(self.client.host)
39 self.assertEqual(self.client.host_app, self.host) 39 self.assertEqual(self.client.host_app, self.host)
40 40
41 41
42 class SatMessageProtocolTest(unittest.TestCase): 42 class SatMessageProtocolTest(unittest.TestCase):
43 43
51 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1"> 51 <message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1">
52 <body>test</body> 52 <body>test</body>
53 </message> 53 </message>
54 """ 54 """
55 stanza = parseXml(xml) 55 stanza = parseXml(xml)
56 self.host.bridge.expectCall("messageNew", u"sender@example.net/house", u"test", u"chat", u"test@example.org/SàT", {}, profile=Const.PROFILE[0]) 56 self.host.bridge.expectCall("messageNew", "sender@example.net/house", "test", "chat", "test@example.org/SàT", {}, profile=Const.PROFILE[0])
57 self.message.onMessage(stanza) 57 self.message.onMessage(stanza)
58 58
59 59
60 class SatRosterProtocolTest(unittest.TestCase): 60 class SatRosterProtocolTest(unittest.TestCase):
61 61
64 self.roster = xmpp.SatRosterProtocol(self.host) 64 self.roster = xmpp.SatRosterProtocol(self.host)
65 self.roster.parent = helpers.FakeClient(self.host) 65 self.roster.parent = helpers.FakeClient(self.host)
66 66
67 def test__registerItem(self): 67 def test__registerItem(self):
68 roster_item = RosterItem(Const.JID[0]) 68 roster_item = RosterItem(Const.JID[0])
69 roster_item.name = u"Test Man" 69 roster_item.name = "Test Man"
70 roster_item.subscriptionTo = True 70 roster_item.subscriptionTo = True
71 roster_item.subscriptionFrom = True 71 roster_item.subscriptionFrom = True
72 roster_item.ask = False 72 roster_item.ask = False
73 roster_item.groups = set([u"Test Group 1", u"Test Group 2", u"Test Group 3"]) 73 roster_item.groups = set(["Test Group 1", "Test Group 2", "Test Group 3"])
74 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]) 74 self.host.bridge.expectCall("newContact", Const.JID_STR[0], {'to': 'True', 'from': 'True', 'ask': 'False', 'name': 'Test Man'}, set(["Test Group 1", "Test Group 2", "Test Group 3"]), Const.PROFILE[0])
75 self.roster._registerItem(roster_item) 75 self.roster._registerItem(roster_item)
76 76
77 77
78 class SatPresenceProtocolTest(unittest.TestCase): 78 class SatPresenceProtocolTest(unittest.TestCase):
79 79