comparison sat/test/test_plugin_misc_groupblog.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 85d3240a400f
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 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org) 6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
18 # You should have received a copy of the GNU Affero General Public License 18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21 """ Plugin groupblogs """ 21 """ Plugin groupblogs """
22 22
23 from constants import Const as C 23 from .constants import Const as C
24 from sat.test import helpers, helpers_plugins 24 from sat.test import helpers, helpers_plugins
25 from sat.plugins import plugin_misc_groupblog 25 from sat.plugins import plugin_misc_groupblog
26 from sat.plugins import plugin_xep_0060 26 from sat.plugins import plugin_xep_0060
27 from sat.plugins import plugin_xep_0277 27 from sat.plugins import plugin_xep_0277
28 from sat.plugins import plugin_xep_0163 28 from sat.plugins import plugin_xep_0163
29 from sat.plugins import plugin_misc_text_syntaxes 29 from sat.plugins import plugin_misc_text_syntaxes
30 from twisted.internet import defer 30 from twisted.internet import defer
31 from twisted.words.protocols.jabber import jid 31 from twisted.words.protocols.jabber import jid
32 import importlib
32 33
33 34
34 NS_PUBSUB = "http://jabber.org/protocol/pubsub" 35 NS_PUBSUB = "http://jabber.org/protocol/pubsub"
35 36
36 DO_NOT_COUNT_COMMENTS = -1 37 DO_NOT_COUNT_COMMENTS = -1
37 38
38 SERVICE = u"pubsub.example.com" 39 SERVICE = "pubsub.example.com"
39 PUBLISHER = u"test@example.org" 40 PUBLISHER = "test@example.org"
40 OTHER_PUBLISHER = u"other@xmpp.net" 41 OTHER_PUBLISHER = "other@xmpp.net"
41 NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER) 42 NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER)
42 OTHER_NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER) 43 OTHER_NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER)
43 ITEM_ID_1 = u"c745a688-9b02-11e3-a1a3-c0143dd4fe51" 44 ITEM_ID_1 = "c745a688-9b02-11e3-a1a3-c0143dd4fe51"
44 COMMENT_ID_1 = u"d745a688-9b02-11e3-a1a3-c0143dd4fe52" 45 COMMENT_ID_1 = "d745a688-9b02-11e3-a1a3-c0143dd4fe52"
45 COMMENT_ID_2 = u"e745a688-9b02-11e3-a1a3-c0143dd4fe53" 46 COMMENT_ID_2 = "e745a688-9b02-11e3-a1a3-c0143dd4fe53"
46 47
47 48
48 def COMMENTS_NODE_ID(publisher=PUBLISHER): 49 def COMMENTS_NODE_ID(publisher=PUBLISHER):
49 return u"urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format( 50 return "urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format(
50 id=ITEM_ID_1, publisher=publisher 51 id=ITEM_ID_1, publisher=publisher
51 ) 52 )
52 53
53 54
54 def COMMENTS_NODE_URL(publisher=PUBLISHER): 55 def COMMENTS_NODE_URL(publisher=PUBLISHER):
55 return u"xmpp:{service}?node={node}".format( 56 return "xmpp:{service}?node={node}".format(
56 service=SERVICE, 57 service=SERVICE,
57 id=ITEM_ID_1, 58 id=ITEM_ID_1,
58 node=COMMENTS_NODE_ID(publisher).replace(":", "%3A").replace("@", "%40"), 59 node=COMMENTS_NODE_ID(publisher).replace(":", "%3A").replace("@", "%40"),
59 ) 60 )
60 61
61 62
62 def ITEM(publisher=PUBLISHER): 63 def ITEM(publisher=PUBLISHER):
63 return u""" 64 return """
64 <item id='{id}' xmlns='{ns}'> 65 <item id='{id}' xmlns='{ns}'>
65 <entry> 66 <entry>
66 <title type='text'>The Uses of This World</title> 67 <title type='text'>The Uses of This World</title>
67 <id>{id}</id> 68 <id>{id}</id>
68 <updated>2003-12-12T17:47:23Z</updated> 69 <updated>2003-12-12T17:47:23Z</updated>
80 comments_node_url=COMMENTS_NODE_URL(publisher), 81 comments_node_url=COMMENTS_NODE_URL(publisher),
81 ) 82 )
82 83
83 84
84 def COMMENT(id_=COMMENT_ID_1): 85 def COMMENT(id_=COMMENT_ID_1):
85 return u""" 86 return """
86 <item id='{id}' xmlns='{ns}'> 87 <item id='{id}' xmlns='{ns}'>
87 <entry> 88 <entry>
88 <title type='text'>The Uses of This World</title> 89 <title type='text'>The Uses of This World</title>
89 <id>{id}</id> 90 <id>{id}</id>
90 <updated>2003-12-12T17:47:23Z</updated> 91 <updated>2003-12-12T17:47:23Z</updated>
111 "comments": COMMENTS_NODE_URL_1, 112 "comments": COMMENTS_NODE_URL_1,
112 "comments_service": SERVICE, 113 "comments_service": SERVICE,
113 "comments_node": COMMENTS_NODE_ID_1, 114 "comments_node": COMMENTS_NODE_ID_1,
114 } 115 }
115 if count != DO_NOT_COUNT_COMMENTS: 116 if count != DO_NOT_COUNT_COMMENTS:
116 res.update({"comments_count": unicode(count)}) 117 res.update({"comments_count": str(count)})
117 return res 118 return res
118 119
119 120
120 def COMMENT_DATA(id_=COMMENT_ID_1): 121 def COMMENT_DATA(id_=COMMENT_ID_1):
121 return { 122 return {
152 class XEP_groupblogTest(helpers.SatTestCase): 153 class XEP_groupblogTest(helpers.SatTestCase):
153 def setUp(self): 154 def setUp(self):
154 self.host = helpers.FakeSAT() 155 self.host = helpers.FakeSAT()
155 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) 156 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
156 self.host.plugins["XEP-0163"] = plugin_xep_0163.XEP_0163(self.host) 157 self.host.plugins["XEP-0163"] = plugin_xep_0163.XEP_0163(self.host)
157 reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error 158 importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
158 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( 159 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(
159 self.host 160 self.host
160 ) 161 )
161 self.host.plugins["XEP-0277"] = plugin_xep_0277.XEP_0277(self.host) 162 self.host.plugins["XEP-0277"] = plugin_xep_0277.XEP_0277(self.host)
162 self.plugin = plugin_misc_groupblog.GroupBlog(self.host) 163 self.plugin = plugin_misc_groupblog.GroupBlog(self.host)
213 ) 214 )
214 return d.addCallback(self.assertEqual, None) 215 return d.addCallback(self.assertEqual, None)
215 216
216 def test_updateGroupBlog(self): 217 def test_updateGroupBlog(self):
217 pub_data = (SERVICE, NODE_ID, ITEM_ID_1) 218 pub_data = (SERVICE, NODE_ID, ITEM_ID_1)
218 new_text = u"silfu23RFWUP)IWNOEIOEFÖ" 219 new_text = "silfu23RFWUP)IWNOEIOEFÖ"
219 220
220 self._initialise(C.PROFILE[0]) 221 self._initialise(C.PROFILE[0])
221 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1]) 222 d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
222 d.addCallback( 223 d.addCallback(
223 lambda __: self.plugin.updateGroupBlog( 224 lambda __: self.plugin.updateGroupBlog(
368 PUBLISHER, {"max_": 1}, profile_key=C.PROFILE[0] 369 PUBLISHER, {"max_": 1}, profile_key=C.PROFILE[0]
369 ) 370 )
370 ) 371 )
371 372
372 def cb(atom): 373 def cb(atom):
373 self.assertIsInstance(atom, unicode) 374 self.assertIsInstance(atom, str)
374 self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>')) 375 self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>'))
375 376
376 return d.addCallback(cb) 377 return d.addCallback(cb)
377 378
378 def test_getMassiveGroupBlogs(self): 379 def test_getMassiveGroupBlogs(self):