comparison src/test/test_plugin_xep_0277.py @ 859:64ec04991d9d

plugin XEP-0277: fix pubsub entry parsing using lxml instead of feed.atom
author souliane <souliane@mailoo.org>
date Sun, 23 Feb 2014 13:54:41 +0100
parents
children 7b4600ad73ad
comparison
equal deleted inserted replaced
858:660b3f5b6c78 859:64ec04991d9d
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # SAT: a jabber client
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 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 sat.test import helpers
23 from sat.plugins import plugin_xep_0277
24 from sat.plugins import plugin_misc_text_syntaxes
25 from sat.tools.xml_tools import ElementParser
26 import re
27
28
29 class XEP_0277Test(helpers.SatTestCase):
30
31 PUBSUB_ENTRY_1 = """
32 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s">
33 <entry>
34 <title type="text">&lt;span&gt;titre&lt;/span&gt;</title>
35 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id>
36 <updated>2014-02-21T16:16:39+02:00</updated>
37 <published>2014-02-21T16:16:38+02:00</published>
38 <content type="text">&lt;p&gt;contenu&lt;/p&gt;texte sans balise&lt;p&gt;autre contenu&lt;/p&gt;</content>
39 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte sans balise<p>autre contenu</p></div></content>
40 <author>
41 <name>test1@souliane.org</name>
42 </author>
43 </entry>
44 </item>
45 """ % plugin_xep_0277.NS_PUBSUB
46
47 PUBSUB_ENTRY_2 = """
48 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s">
49 <entry xmlns=''>
50 <title type="text">&lt;div&gt;titre&lt;/div&gt;</title>
51 <title type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><div style="background-image: url('xxx');">titre</div></div></title>
52 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id>
53 <updated>2014-02-21T16:16:39+02:00</updated>
54 <published>2014-02-21T16:16:38+02:00</published>
55 <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>
56 <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>
57 <author>
58 <nick>test1@souliane.org</nick>
59 </author>
60 </entry>
61 </item>
62 """ % plugin_xep_0277.NS_PUBSUB
63
64 def setUp(self):
65 self.host = helpers.FakeSAT()
66
67 class XEP_0163(object):
68 def __init__(self, host):
69 pass
70
71 def addPEPEvent(self, *args):
72 pass
73 self.host.plugins["XEP-0163"] = XEP_0163(self.host)
74 self.host.plugins["TEXT-SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
75 self.plugin = plugin_xep_0277.XEP_0277(self.host)
76
77 def test_item2mbdata_1(self):
78 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
79 'title': '<span>titre</span>',
80 'updated': '1392992199.0',
81 'published': '1392992198.0',
82 'content': '<p>contenu</p>texte sans balise<p>autre contenu</p>',
83 'content_xhtml': '<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>',
84 'author': 'test1@souliane.org'
85 }
86 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_1))
87 d.addCallback(self.assertEqual, expected)
88 return d
89
90 def test_item2mbdata_2(self):
91 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
92 'title': '<div>titre</div>',
93 'title_xhtml': '<div style="">titre</div>',
94 'updated': '1392992199.0',
95 'published': '1392992198.0',
96 'content': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
97 'content_xhtml': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
98 'author': 'test1@souliane.org'
99 }
100 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_2))
101 d.addCallback(self.assertEqual, expected)
102 return d