comparison src/test/test_plugin_xep_0277.py @ 1913:ee1125fffba8

plugin XEP-0277, test: set keys of data dict as unicode + fix the tests
author souliane <souliane@mailoo.org>
date Fri, 18 Mar 2016 08:58:22 +0100
parents 55440ee00905
children 2daf7b4c6756
comparison
equal deleted inserted replaced
1912:c38bcc0343b6 1913:ee1125fffba8
22 from sat.test import helpers 22 from sat.test import helpers
23 from sat.plugins import plugin_xep_0277 23 from sat.plugins import plugin_xep_0277
24 from sat.plugins import plugin_xep_0060 24 from sat.plugins import plugin_xep_0060
25 from sat.plugins import plugin_misc_text_syntaxes 25 from sat.plugins import plugin_misc_text_syntaxes
26 from sat.tools.xml_tools import ElementParser 26 from sat.tools.xml_tools import ElementParser
27 from wokkel.pubsub import NS_PUBSUB
27 28
28 29
29 class XEP_0277Test(helpers.SatTestCase): 30 class XEP_0277Test(helpers.SatTestCase):
30 31
31 PUBSUB_ENTRY_1 = """ 32 PUBSUB_ENTRY_1 = u"""
32 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s"> 33 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51">
33 <entry> 34 <entry xmlns="%s">
34 <title type="text">&lt;span&gt;titre&lt;/span&gt;</title> 35 <title type="text">&lt;span&gt;titre&lt;/span&gt;</title>
35 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id> 36 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id>
36 <updated>2014-02-21T16:16:39+02:00</updated> 37 <updated>2014-02-21T16:16:39+02:00</updated>
37 <published>2014-02-21T16:16:38+02:00</published> 38 <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="text">&lt;p&gt;contenu&lt;/p&gt;texte sans balise&lt;p&gt;autre contenu&lt;/p&gt;</content>
40 <author> 41 <author>
41 <name>test1@souliane.org</name> 42 <name>test1@souliane.org</name>
42 </author> 43 </author>
43 </entry> 44 </entry>
44 </item> 45 </item>
45 """ % plugin_xep_0277.NS_PUBSUB 46 """ % plugin_xep_0277.NS_ATOM
46 47
47 PUBSUB_ENTRY_2 = """ 48 PUBSUB_ENTRY_2 = u"""
48 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51" xmlns="%s"> 49 <item id="c745a688-9b02-11e3-a1a3-c0143dd4fe51">
49 <entry xmlns=''> 50 <entry xmlns='%s'>
50 <title type="text">&lt;div&gt;titre&lt;/div&gt;</title> 51 <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 <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 <id>c745a688-9b02-11e3-a1a3-c0143dd4fe51</id>
53 <updated>2014-02-21T16:16:39+02:00</updated> 54 <updated>2014-02-21T16:16:39+02:00</updated>
54 <published>2014-02-21T16:16:38+02:00</published> 55 <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="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 <content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml"><p>contenu</p>texte dans balise<p>autre contenu</p></div></content>
57 <author> 58 <author>
58 <nick>test1@souliane.org</nick> 59 <name>test1@souliane.org</name>
60 <nick>test1</nick>
59 </author> 61 </author>
60 </entry> 62 </entry>
61 </item> 63 </item>
62 """ % plugin_xep_0277.NS_PUBSUB 64 """ % plugin_xep_0277.NS_ATOM
63 65
64 def setUp(self): 66 def setUp(self):
65 self.host = helpers.FakeSAT() 67 self.host = helpers.FakeSAT()
66 68
67 class XEP_0163(object): 69 class XEP_0163(object):
75 reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error 77 reload(plugin_misc_text_syntaxes) # reload the plugin to avoid conflict error
76 self.host.plugins["TEXT-SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(self.host) 78 self.host.plugins["TEXT-SYNTAXES"] = plugin_misc_text_syntaxes.TextSyntaxes(self.host)
77 self.plugin = plugin_xep_0277.XEP_0277(self.host) 79 self.plugin = plugin_xep_0277.XEP_0277(self.host)
78 80
79 def test_item2mbdata_1(self): 81 def test_item2mbdata_1(self):
80 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51', 82 expected = {u'id': u'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
81 'title': '<span>titre</span>', 83 u'atom_id': u'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
82 'updated': '1392992199.0', 84 u'title': u'<span>titre</span>',
83 'published': '1392992198.0', 85 u'updated': u'1392992199.0',
84 'content': '<p>contenu</p>texte sans balise<p>autre contenu</p>', 86 u'published': u'1392992198.0',
85 'content_xhtml': '<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>', 87 u'content': u'<p>contenu</p>texte sans balise<p>autre contenu</p>',
86 'author': 'test1@souliane.org' 88 u'content_xhtml': u'<div><p>contenu</p>texte sans balise<p>autre contenu</p></div>',
89 u'author': u'test1@souliane.org'
87 } 90 }
88 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_1)) 91 item_elt = ElementParser()(self.PUBSUB_ENTRY_1, namespace=NS_PUBSUB).elements().next()
92 d = self.plugin.item2mbdata(item_elt)
89 d.addCallback(self.assertEqual, expected) 93 d.addCallback(self.assertEqual, expected)
90 return d 94 return d
91 95
92 def test_item2mbdata_2(self): 96 def test_item2mbdata_2(self):
93 expected = {'id': 'c745a688-9b02-11e3-a1a3-c0143dd4fe51', 97 expected = {u'id': u'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
94 'title': '<div>titre</div>', 98 u'atom_id': u'c745a688-9b02-11e3-a1a3-c0143dd4fe51',
95 'title_xhtml': '<div style="">titre</div>', 99 u'title': u'<div>titre</div>',
96 'updated': '1392992199.0', 100 u'title_xhtml': u'<div><div style="">titre</div></div>',
97 'published': '1392992198.0', 101 u'updated': u'1392992199.0',
98 'content': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>', 102 u'published': u'1392992198.0',
99 'content_xhtml': '<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>', 103 u'content': u'<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
100 'author': 'test1@souliane.org' 104 u'content_xhtml': u'<div><p>contenu</p>texte dans balise<p>autre contenu</p></div>',
105 u'author': u'test1@souliane.org'
101 } 106 }
102 d = self.plugin.item2mbdata(ElementParser()(self.PUBSUB_ENTRY_2)) 107 item_elt = ElementParser()(self.PUBSUB_ENTRY_2, namespace=NS_PUBSUB).elements().next()
108 d = self.plugin.item2mbdata(item_elt)
103 d.addCallback(self.assertEqual, expected) 109 d.addCallback(self.assertEqual, expected)
104 return d 110 return d