annotate src/test/test_plugin_xep_0277.py @ 1382:b01efa1c0f5e

quick_frontend, primitivus: better PEP-8 compliance + remove/rename some (Quick)Chat attributes: - remove QuickChat.id, use QuickChat.target instead - rename Chat.present_panel to Chat.occupants_panel - rename Chat.present_wid to Chat.occupants_list
author souliane <souliane@mailoo.org>
date Sun, 22 Mar 2015 14:20:19 +0100
parents 7b4600ad73ad
children 069ad98b360d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
859
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
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
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
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
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
24 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
25 from sat.tools.xml_tools import ElementParser
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
26
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
27
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
28 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
29
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
30 PUBSUB_ENTRY_1 = """
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
31 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s">
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
32 <entry>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
33 <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
34 <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
35 <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
36 <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
37 <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
38 <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
39 <author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
40 <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
41 </author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
42 </entry>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
43 </item>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
44 """ % plugin_xep_0277.NS_PUBSUB
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
45
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
46 PUBSUB_ENTRY_2 = """
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
47 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s">
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
48 <entry xmlns=''>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
49 <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
50 <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
51 <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
52 <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
53 <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
54 <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>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
55 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div><p>contenu</p>texte dans balise<p>autre contenu</p></div></div></content>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
56 <author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
57 <nick>test1@souliane.org</nick>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
58 </author>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
59 </entry>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
60 </item>
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
61 """ % plugin_xep_0277.NS_PUBSUB
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
62
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
63 def setUp(self):
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
64 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
65
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
66 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
67 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
68 pass
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
69
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
70 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
71 pass
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
72 self.host.plugins["XEP-0163"] = XEP_0163(self.host)
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
73 self.host.plugins["TEXT-SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
74 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
75
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
76 def test_item2mbdata_1(self):
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
77 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
78 'title': '<span>titre</span>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
79 'updated': '1392992199.0',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
80 'published': '1392992198.0',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
81 'content': '<p>contenu</p>texte sans balise<p>autre contenu</p>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
82 'content_xhtml': '<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
83 'author': 'test1@souliane.org'
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
84 }
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
85 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_1))
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
86 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
87 return d
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
88
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
89 def test_item2mbdata_2(self):
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
90 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
91 'title': '<div>titre</div>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
92 'title_xhtml': '<div style="">titre</div>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
93 'updated': '1392992199.0',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
94 'published': '1392992198.0',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
95 'content': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
96 'content_xhtml': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
97 'author': 'test1@souliane.org'
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
98 }
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
99 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_2))
64ec04991d9d plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
souliane <souliane@mailoo.org>
parents:
diff changeset
100 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
101 return d