annotate sat/test/test_plugin_xep_0277.py @ 2821:3d735e0ab2fa

plugin OTR: ignore messages from sender without resource or from own jid
author Goffi <goffi@goffi.org>
date Fri, 01 Mar 2019 12:13:55 +0100
parents 85d3240a400f
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1913
diff changeset
1 #!/usr/bin/env python2
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 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
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
22 from sat.test import helpers
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from sat.plugins import plugin_xep_0277
1910
55440ee00905 test: update some tests
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
24 from sat.plugins import plugin_xep_0060
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from sat.plugins import plugin_misc_text_syntaxes
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from sat.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
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
28
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 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
31
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
32 PUBSUB_ENTRY_1 = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 u"""
1913
ee1125fffba8 plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents: 1910
diff changeset
34 <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
35 <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
36 <title type="text">&lt;span&gt;titre&lt;/span&gt;</title>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
37 <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
38 <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
39 <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
40 <content type="text">&lt;p&gt;contenu&lt;/p&gt;texte sans balise&lt;p&gt;autre contenu&lt;/p&gt;</content>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
41 <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
42 <author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
43 <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
44 </author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
45 </entry>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
46 </item>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 """
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 % plugin_xep_0277.NS_ATOM
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 )
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
50
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 PUBSUB_ENTRY_2 = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 u"""
1913
ee1125fffba8 plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents: 1910
diff changeset
53 <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
54 <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
55 <title type="text">&lt;div&gt;titre&lt;/div&gt;</title>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
56 <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
57 <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
58 <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
59 <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
60 <content type="text">&lt;div&gt;&lt;p&gt;contenu&lt;/p&gt;texte dans balise&lt;p&gt;autre contenu&lt;/p&gt;&lt;/div&gt;</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
61 <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
62 <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
63 <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
64 <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
65 </author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
66 </entry>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
67 </item>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 """
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 % plugin_xep_0277.NS_ATOM
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 )
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
71
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
72 def setUp(self):
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
73 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
74
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
75 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
76 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
77 pass
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
78
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
79 def addPEPEvent(self, *args):
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
80 pass
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81
1910
55440ee00905 test: update some tests
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
82 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
83 self.host.plugins["XEP-0163"] = XEP_0163(self.host)
1910
55440ee00905 test: update some tests
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
84 reload(plugin_misc_text_syntaxes) # 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
85 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
86 self.host
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 )
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
88 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
89
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
90 def test_item2mbdata_1(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 expected = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
92 u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 u"title": u"<span>titre</span>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 u"updated": u"1392992199.0",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 u"published": u"1392992198.0",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 u"content": u"<p>contenu</p>texte sans balise<p>autre contenu</p>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 u"content_xhtml": u"<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 u"author": u"test1@souliane.org",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 item_elt = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements().next()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 )
1913
ee1125fffba8 plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents: 1910
diff changeset
104 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
105 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
106 return d
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
107
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
108 def test_item2mbdata_2(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 expected = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 u"id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 u"atom_id": u"c745a688-9b02-11e3-a1a3-c0143dd4fe51",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 u"title": u"<div>titre</div>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 u"title_xhtml": u'<div><div style="">titre</div></div>',
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 u"updated": u"1392992199.0",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 u"published": u"1392992198.0",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 u"content": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 u"content_xhtml": u"<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 u"author": u"test1@souliane.org",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 item_elt = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements().next()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 )
1913
ee1125fffba8 plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
souliane <souliane@mailoo.org>
parents: 1910
diff changeset
123 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
124 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
125 return d