Mercurial > libervia-backend
comparison sat/test/test_plugin_xep_0277.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 | 6 |
23 from sat.plugins import plugin_xep_0277 | 23 from sat.plugins import plugin_xep_0277 |
24 from sat.plugins import plugin_xep_0060 | 24 from sat.plugins import plugin_xep_0060 |
25 from sat.plugins import plugin_misc_text_syntaxes | 25 from sat.plugins import plugin_misc_text_syntaxes |
26 from sat.tools.xml_tools import ElementParser | 26 from sat.tools.xml_tools import ElementParser |
27 from wokkel.pubsub import NS_PUBSUB | 27 from wokkel.pubsub import NS_PUBSUB |
28 import importlib | |
28 | 29 |
29 | 30 |
30 class XEP_0277Test(helpers.SatTestCase): | 31 class XEP_0277Test(helpers.SatTestCase): |
31 | 32 |
32 PUBSUB_ENTRY_1 = ( | 33 PUBSUB_ENTRY_1 = ( |
33 u""" | 34 """ |
34 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> | 35 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> |
35 <entry xmlns="%s"> | 36 <entry xmlns="%s"> |
36 <title type="text"><span>titre</span></title> | 37 <title type="text"><span>titre</span></title> |
37 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> | 38 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> |
38 <updated>2014-02-21T16:16:39+02:00</updated> | 39 <updated>2014-02-21T16:16:39+02:00</updated> |
47 """ | 48 """ |
48 % plugin_xep_0277.NS_ATOM | 49 % plugin_xep_0277.NS_ATOM |
49 ) | 50 ) |
50 | 51 |
51 PUBSUB_ENTRY_2 = ( | 52 PUBSUB_ENTRY_2 = ( |
52 u""" | 53 """ |
53 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> | 54 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> |
54 <entry xmlns='%s'> | 55 <entry xmlns='%s'> |
55 <title type="text"><div>titre</div></title> | 56 <title type="text"><div>titre</div></title> |
56 <title type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div style="background-image: url('xxx');">titre</div></div></title> | 57 <title type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div style="background-image: url('xxx');">titre</div></div></title> |
57 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> | 58 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> |
79 def addPEPEvent(self, *args): | 80 def addPEPEvent(self, *args): |
80 pass | 81 pass |
81 | 82 |
82 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) | 83 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) |
83 self.host.plugins["XEP-0163"] = XEP_0163(self.host) | 84 self.host.plugins["XEP-0163"] = XEP_0163(self.host) |
84 reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error | 85 importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error |
85 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( | 86 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( |
86 self.host | 87 self.host |
87 ) | 88 ) |
88 self.plugin = plugin_xep_0277.XEP_0277(self.host) | 89 self.plugin = plugin_xep_0277.XEP_0277(self.host) |
89 | 90 |
90 def test_item2mbdata_1(self): | 91 def test_item2mbdata_1(self): |
91 expected = { | 92 expected = { |
92 u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51", | 93 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
93 u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51", | 94 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
94 u"title": u"<span>titre</span>", | 95 "title": "<span>titre</span>", |
95 u"updated": u"1392992199.0", | 96 "updated": "1392992199.0", |
96 u"published": u"1392992198.0", | 97 "published": "1392992198.0", |
97 u"content": u"<p>contenu</p>texte sans balise<p>autre contenu</p>", | 98 "content": "<p>contenu</p>texte sans balise<p>autre contenu</p>", |
98 u"content_xhtml": u"<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>", | 99 "content_xhtml": "<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>", |
99 u"author": u"test1@souliane.org", | 100 "author": "test1@souliane.org", |
100 } | 101 } |
101 item_elt = ( | 102 item_elt = ( |
102 ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements().next() | 103 next(ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements()) |
103 ) | 104 ) |
104 d = self.plugin.item2mbdata(item_elt) | 105 d = self.plugin.item2mbdata(item_elt) |
105 d.addCallback(self.assertEqual, expected) | 106 d.addCallback(self.assertEqual, expected) |
106 return d | 107 return d |
107 | 108 |
108 def test_item2mbdata_2(self): | 109 def test_item2mbdata_2(self): |
109 expected = { | 110 expected = { |
110 u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51", | 111 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
111 u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51", | 112 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
112 u"title": u"<div>titre</div>", | 113 "title": "<div>titre</div>", |
113 u"title_xhtml": u'<div><div style="">titre</div></div>', | 114 "title_xhtml": '<div><div style="">titre</div></div>', |
114 u"updated": u"1392992199.0", | 115 "updated": "1392992199.0", |
115 u"published": u"1392992198.0", | 116 "published": "1392992198.0", |
116 u"content": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", | 117 "content": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", |
117 u"content_xhtml": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", | 118 "content_xhtml": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", |
118 u"author": u"test1@souliane.org", | 119 "author": "test1@souliane.org", |
119 } | 120 } |
120 item_elt = ( | 121 item_elt = ( |
121 ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements().next() | 122 next(ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements()) |
122 ) | 123 ) |
123 d = self.plugin.item2mbdata(item_elt) | 124 d = self.plugin.item2mbdata(item_elt) |
124 d.addCallback(self.assertEqual, expected) | 125 d.addCallback(self.assertEqual, expected) |
125 return d | 126 return d |