Mercurial > libervia-backend
annotate libervia/backend/test/test_plugin_xep_0277.py @ 4309:b56b1eae7994
component email gateway: add multicasting:
XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033
metadata are converted to suitable Email headers and vice versa.
Email address and JID are both supported, and delivery is done by the gateway when
suitable on incoming messages.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # SAT: a jabber client |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 """ Plugin XEP-0277 tests """ |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
22 from libervia.backend.test import helpers |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.plugins import plugin_xep_0277 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.plugins import plugin_xep_0060 |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.plugins import plugin_misc_text_syntaxes |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.tools.xml_tools import ElementParser |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
27 from wokkel.pubsub import NS_PUBSUB |
3028 | 28 import importlib |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 class XEP_0277Test(helpers.SatTestCase): |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
33 PUBSUB_ENTRY_1 = ( |
3028 | 34 """ |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
35 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> |
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
36 <entry xmlns="%s"> |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 <title type="text"><span>titre</span></title> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
38 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
39 <updated>2014-02-21T16:16:39+02:00</updated> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
40 <published>2014-02-21T16:16:38+02:00</published> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
41 <content type="text"><p>contenu</p>texte sans balise<p>autre contenu</p></content> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
42 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte sans balise<p>autre contenu</p></div></content> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
43 <author> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
44 <name>test1@souliane.org</name> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
45 </author> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
46 </entry> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
47 </item> |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 """ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 % plugin_xep_0277.NS_ATOM |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 ) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
51 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 PUBSUB_ENTRY_2 = ( |
3028 | 53 """ |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
54 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51"> |
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
55 <entry xmlns='%s'> |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 <title type="text"><div>titre</div></title> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
57 <title type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div style="background-image: url('xxx');">titre</div></div></title> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
58 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
59 <updated>2014-02-21T16:16:39+02:00</updated> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 <published>2014-02-21T16:16:38+02:00</published> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
61 <content type="text"><div><p>contenu</p>texte dans balise<p>autre contenu</p></div></content> |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
62 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte dans balise<p>autre contenu</p></div></content> |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 <author> |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
64 <name>test1@souliane.org</name> |
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
65 <nick>test1</nick> |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 </author> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 </entry> |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 </item> |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 """ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 % plugin_xep_0277.NS_ATOM |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 ) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 def setUp(self): |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 self.host = helpers.FakeSAT() |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 class XEP_0163(object): |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 def __init__(self, host): |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 pass |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
80 def add_pep_event(self, *args): |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 pass |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 |
1910 | 83 self.host.plugins["XEP-0060"] = plugin_xep_0060.XEP_0060(self.host) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 self.host.plugins["XEP-0163"] = XEP_0163(self.host) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
85 importlib.reload( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
86 plugin_misc_text_syntaxes |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
87 ) # reload the plugin to avoid conflict error |
2780
85d3240a400f
plugin text syntaxes: changed import name to TEXT_SYNTAX (better with underscore for autocompletion)
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
88 self.host.plugins["TEXT_SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 self.host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
90 ) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 self.plugin = plugin_xep_0277.XEP_0277(self.host) |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 def test_item2mbdata_1(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 expected = { |
3028 | 95 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
96 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
97 "title": "<span>titre</span>", | |
98 "updated": "1392992199.0", | |
99 "published": "1392992198.0", | |
100 "content": "<p>contenu</p>texte sans balise<p>autre contenu</p>", | |
101 "content_xhtml": "<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>", | |
102 "author": "test1@souliane.org", | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 } |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
104 item_elt = next( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
105 ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
106 ) |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
107 d = self.plugin.item2mbdata(item_elt) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 d.addCallback(self.assertEqual, expected) |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 return d |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 def test_item2mbdata_2(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 expected = { |
3028 | 113 "id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", |
114 "atom_id": "c745a688-9b02-11e3-a1a3-c0143dd4fe51", | |
115 "title": "<div>titre</div>", | |
116 "title_xhtml": '<div><div style="">titre</div></div>', | |
117 "updated": "1392992199.0", | |
118 "published": "1392992198.0", | |
119 "content": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", | |
120 "content_xhtml": "<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>", | |
121 "author": "test1@souliane.org", | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 } |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
123 item_elt = next( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
124 ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 ) |
1913
ee1125fffba8
plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents:
1910
diff
changeset
|
126 d = self.plugin.item2mbdata(item_elt) |
859
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 d.addCallback(self.assertEqual, expected) |
64ec04991d9d
plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 return d |