diff 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
line wrap: on
line diff
--- a/sat/test/test_plugin_misc_groupblog.py	Wed Jul 31 11:31:22 2019 +0200
+++ b/sat/test/test_plugin_misc_groupblog.py	Tue Aug 13 19:08:41 2019 +0200
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
 # -*- coding: utf-8 -*-
 
 # SAT: a jabber client
@@ -20,7 +20,7 @@
 
 """ Plugin groupblogs """
 
-from constants import Const as C
+from .constants import Const as C
 from sat.test import helpers, helpers_plugins
 from sat.plugins import plugin_misc_groupblog
 from sat.plugins import plugin_xep_0060
@@ -29,30 +29,31 @@
 from sat.plugins import plugin_misc_text_syntaxes
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
+import importlib
 
 
 NS_PUBSUB = "http://jabber.org/protocol/pubsub"
 
 DO_NOT_COUNT_COMMENTS = -1
 
-SERVICE = u"pubsub.example.com"
-PUBLISHER = u"test@example.org"
-OTHER_PUBLISHER = u"other@xmpp.net"
-NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER)
-OTHER_NODE_ID = u"urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER)
-ITEM_ID_1 = u"c745a688-9b02-11e3-a1a3-c0143dd4fe51"
-COMMENT_ID_1 = u"d745a688-9b02-11e3-a1a3-c0143dd4fe52"
-COMMENT_ID_2 = u"e745a688-9b02-11e3-a1a3-c0143dd4fe53"
+SERVICE = "pubsub.example.com"
+PUBLISHER = "test@example.org"
+OTHER_PUBLISHER = "other@xmpp.net"
+NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=PUBLISHER)
+OTHER_NODE_ID = "urn:xmpp:groupblog:{publisher}".format(publisher=OTHER_PUBLISHER)
+ITEM_ID_1 = "c745a688-9b02-11e3-a1a3-c0143dd4fe51"
+COMMENT_ID_1 = "d745a688-9b02-11e3-a1a3-c0143dd4fe52"
+COMMENT_ID_2 = "e745a688-9b02-11e3-a1a3-c0143dd4fe53"
 
 
 def COMMENTS_NODE_ID(publisher=PUBLISHER):
-    return u"urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format(
+    return "urn:xmpp:comments:_{id}__urn:xmpp:groupblog:{publisher}".format(
         id=ITEM_ID_1, publisher=publisher
     )
 
 
 def COMMENTS_NODE_URL(publisher=PUBLISHER):
-    return u"xmpp:{service}?node={node}".format(
+    return "xmpp:{service}?node={node}".format(
         service=SERVICE,
         id=ITEM_ID_1,
         node=COMMENTS_NODE_ID(publisher).replace(":", "%3A").replace("@", "%40"),
@@ -60,7 +61,7 @@
 
 
 def ITEM(publisher=PUBLISHER):
-    return u"""
+    return """
           <item id='{id}' xmlns='{ns}'>
             <entry>
               <title type='text'>The Uses of This World</title>
@@ -82,7 +83,7 @@
 
 
 def COMMENT(id_=COMMENT_ID_1):
-    return u"""
+    return """
           <item id='{id}' xmlns='{ns}'>
             <entry>
               <title type='text'>The Uses of This World</title>
@@ -113,7 +114,7 @@
         "comments_node": COMMENTS_NODE_ID_1,
     }
     if count != DO_NOT_COUNT_COMMENTS:
-        res.update({"comments_count": unicode(count)})
+        res.update({"comments_count": str(count)})
     return res
 
 
@@ -154,7 +155,7 @@
         self.host = helpers.FakeSAT()
         self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host)
         self.host.plugins["XEP-0163"] = plugin_xep_0163.XEP_0163(self.host)
-        reload(plugin_misc_text_syntaxes)  # reload the plugin to avoid conflict error
+        importlib.reload(plugin_misc_text_syntaxes)  # reload the plugin to avoid conflict error
         self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(
             self.host
         )
@@ -215,7 +216,7 @@
 
     def test_updateGroupBlog(self):
         pub_data = (SERVICE, NODE_ID, ITEM_ID_1)
-        new_text = u"silfu23RFWUP)IWNOEIOEFÖ"
+        new_text = "silfu23RFWUP)IWNOEIOEFÖ"
 
         self._initialise(C.PROFILE[0])
         d = self.psclient.publish(SERVICE, NODE_ID, [ITEM_1])
@@ -370,7 +371,7 @@
         )
 
         def cb(atom):
-            self.assertIsInstance(atom, unicode)
+            self.assertIsInstance(atom, str)
             self.assertTrue(atom.startswith('<?xml version="1.0" encoding="utf-8"?>'))
 
         return d.addCallback(cb)