comparison sat/test/test_plugin_xep_0334.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 378188abe941
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
25 from sat.plugins.plugin_xep_0334 import XEP_0334 25 from sat.plugins.plugin_xep_0334 import XEP_0334
26 from twisted.internet import defer 26 from twisted.internet import defer
27 from wokkel.generic import parseXml 27 from wokkel.generic import parseXml
28 from sat.core import exceptions 28 from sat.core import exceptions
29 29
30 HINTS = ('no-permanent-storage', 'no-storage', 'no-copy') 30 HINTS = ("no-permanent-storage", "no-storage", "no-copy")
31 31
32 32
33 class XEP_0334Test(helpers.SatTestCase): 33 class XEP_0334Test(helpers.SatTestCase):
34
35 def setUp(self): 34 def setUp(self):
36 self.host = helpers.FakeSAT() 35 self.host = helpers.FakeSAT()
37 self.plugin = XEP_0334(self.host) 36 self.plugin = XEP_0334(self.host)
38 37
39 def test_messageSendTrigger(self): 38 def test_messageSendTrigger(self):
44 type='chat'> 43 type='chat'>
45 <body>text</body> 44 <body>text</body>
46 %s 45 %s
47 </message> 46 </message>
48 """ 47 """
49 original_xml = template_xml % '' 48 original_xml = template_xml % ""
50 49
51 d_list = [] 50 d_list = []
52 51
53 def cb(data, expected_xml): 52 def cb(data, expected_xml):
54 result_xml = data['xml'].toXml().encode("utf-8") 53 result_xml = data["xml"].toXml().encode("utf-8")
55 self.assertEqualXML(result_xml, expected_xml, True) 54 self.assertEqualXML(result_xml, expected_xml, True)
56 55
57 for key in (HINTS + ('', 'dummy_hint')): 56 for key in HINTS + ("", "dummy_hint"):
58 mess_data = {'xml': parseXml(original_xml.encode("utf-8")), 57 mess_data = {
59 'extra': {key: True} 58 "xml": parseXml(original_xml.encode("utf-8")),
60 } 59 "extra": {key: True},
60 }
61 treatments = defer.Deferred() 61 treatments = defer.Deferred()
62 self.plugin.messageSendTrigger(self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments) 62 self.plugin.messageSendTrigger(
63 self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments
64 )
63 if treatments.callbacks: # the trigger added a callback 65 if treatments.callbacks: # the trigger added a callback
64 expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key) 66 expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)
65 treatments.addCallback(cb, expected_xml) 67 treatments.addCallback(cb, expected_xml)
66 treatments.callback(mess_data) 68 treatments.callback(mess_data)
67 d_list.append(treatments) 69 d_list.append(treatments)
85 def eb(failure): 87 def eb(failure):
86 failure.trap(exceptions.SkipHistory) 88 failure.trap(exceptions.SkipHistory)
87 89
88 d_list = [] 90 d_list = []
89 91
90 for key in (HINTS + ('dummy_hint',)): 92 for key in HINTS + ("dummy_hint",):
91 message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)) 93 message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key))
92 post_treat = defer.Deferred() 94 post_treat = defer.Deferred()
93 self.plugin.messageReceivedTrigger(self.host.getClient(C.PROFILE[0]), message, post_treat) 95 self.plugin.messageReceivedTrigger(
96 self.host.getClient(C.PROFILE[0]), message, post_treat
97 )
94 if post_treat.callbacks: 98 if post_treat.callbacks:
95 assert(key in ('no-permanent-storage', 'no-storage')) 99 assert key in ("no-permanent-storage", "no-storage")
96 post_treat.addCallbacks(cb, eb) 100 post_treat.addCallbacks(cb, eb)
97 post_treat.callback(None) 101 post_treat.callback(None)
98 d_list.append(post_treat) 102 d_list.append(post_treat)
99 else: 103 else:
100 assert(key not in ('no-permanent-storage', 'no-storage')) 104 assert key not in ("no-permanent-storage", "no-storage")
101 105
102 return defer.DeferredList(d_list) 106 return defer.DeferredList(d_list)