Mercurial > libervia-backend
comparison libervia/backend/test/test_plugin_xep_0277.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/test/test_plugin_xep_0277.py@524856bd7b19 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 # SAT: a jabber client | |
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
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/>. | |
19 | |
20 """ Plugin XEP-0277 tests """ | |
21 | |
22 from libervia.backend.test import helpers | |
23 from libervia.backend.plugins import plugin_xep_0277 | |
24 from libervia.backend.plugins import plugin_xep_0060 | |
25 from libervia.backend.plugins import plugin_misc_text_syntaxes | |
26 from libervia.backend.tools.xml_tools import ElementParser | |
27 from wokkel.pubsub import NS_PUBSUB | |
28 import importlib | |
29 | |
30 | |
31 class XEP_0277Test(helpers.SatTestCase): | |
32 | |
33 PUBSUB_ENTRY_1 = ( | |
34 """ | |
35 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> | |
36 <entry xmlns="%s"> | |
37 <title type="text"><span>titre</span></title> | |
38 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> | |
39 <updated>2014-02-21T16:16:39+02:00</updated> | |
40 <published>2014-02-21T16:16:38+02:00</published> | |
41 <content type="text"><p>contenu</p>texte sans balise<p>autre contenu</p></content> | |
42 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte sans balise<p>autre contenu</p></div></content> | |
43 <author> | |
44 <name>test1@souliane.org</name> | |
45 </author> | |
46 </entry> | |
47 </item> | |
48 """ | |
49 % plugin_xep_0277.NS_ATOM | |
50 ) | |
51 | |
52 PUBSUB_ENTRY_2 = ( | |
53 """ | |
54 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> | |
55 <entry xmlns='%s'> | |
56 <title type="text"><div>titre</div></title> | |
57 <title type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div style="background-image: url('xxx');">titre</div></div></title> | |
58 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> | |
59 <updated>2014-02-21T16:16:39+02:00</updated> | |
60 <published>2014-02-21T16:16:38+02:00</published> | |
61 <content type="text"><div><p>contenu</p>texte dans balise<p>autre contenu</p></div></content> | |
62 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte dans balise<p>autre contenu</p></div></content> | |
63 <author> | |
64 <name>test1@souliane.org</name> | |
65 <nick>test1</nick> | |
66 </author> | |
67 </entry> | |
68 </item> | |
69 """ | |
70 % plugin_xep_0277.NS_ATOM | |
71 ) | |
72 | |
73 def setUp(self): | |
74 self.host = helpers.FakeSAT() | |
75 | |
76 class XEP_0163(object): | |
77 def __init__(self, host): | |
78 pass | |
79 | |
80 def add_pep_event(self, *args): | |
81 pass | |
82 | |
83 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) | |
84 self.host.plugins["XEP-0163"] = XEP_0163(self.host) | |
85 importlib.reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error | |
86 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( | |
87 self.host | |
88 ) | |
89 self.plugin = plugin_xep_0277.XEP_0277(self.host) | |
90 | |
91 def test_item2mbdata_1(self): | |
92 expected = { | |
93 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
94 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
95 "title": "<span>titre</span>", | |
96 "updated": "1392992199.0", | |
97 "published": "1392992198.0", | |
98 "content": "<p>contenu</p>texte sans balise<p>autre contenu</p>", | |
99 "content_xhtml": "<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>", | |
100 "author": "test1@souliane.org", | |
101 } | |
102 item_elt = ( | |
103 next(ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements()) | |
104 ) | |
105 d = self.plugin.item2mbdata(item_elt) | |
106 d.addCallback(self.assertEqual, expected) | |
107 return d | |
108 | |
109 def test_item2mbdata_2(self): | |
110 expected = { | |
111 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
112 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
113 "title": "<div>titre</div>", | |
114 "title_xhtml": '<div><div style="">titre</div></div>', | |
115 "updated": "1392992199.0", | |
116 "published": "1392992198.0", | |
117 "content": "<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>", | |
119 "author": "test1@souliane.org", | |
120 } | |
121 item_elt = ( | |
122 next(ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements()) | |
123 ) | |
124 d = self.plugin.item2mbdata(item_elt) | |
125 d.addCallback(self.assertEqual, expected) | |
126 return d |