comparison sat/test/test_plugin_xep_0085.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
28 from twisted.internet import defer 28 from twisted.internet import defer
29 from wokkel.generic import parseXml 29 from wokkel.generic import parseXml
30 30
31 31
32 class XEP_0085Test(helpers.SatTestCase): 32 class XEP_0085Test(helpers.SatTestCase):
33
34 def setUp(self): 33 def setUp(self):
35 self.host = helpers.FakeSAT() 34 self.host = helpers.FakeSAT()
36 self.plugin = plugin.XEP_0085(self.host) 35 self.plugin = plugin.XEP_0085(self.host)
37 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0]) 36 self.host.memory.setParam(
37 plugin.PARAM_NAME,
38 True,
39 plugin.PARAM_KEY,
40 C.NO_SECURITY_LIMIT,
41 Const.PROFILE[0],
42 )
38 43
39 def test_messageReceived(self): 44 def test_messageReceived(self):
40 for state in plugin.CHAT_STATES: 45 for state in plugin.CHAT_STATES:
41 xml = u""" 46 xml = u"""
42 <message type="chat" from="%s" to="%s" id="test_1"> 47 <message type="chat" from="%s" to="%s" id="test_1">
43 %s 48 %s
44 <%s xmlns='%s'/> 49 <%s xmlns='%s'/>
45 </message> 50 </message>
46 """ % (Const.JID_STR[1], 51 """ % (
47 Const.JID_STR[0], 52 Const.JID_STR[1],
48 "<body>test</body>" if state == "active" else "", 53 Const.JID_STR[0],
49 state, plugin.NS_CHAT_STATES) 54 "<body>test</body>" if state == "active" else "",
55 state,
56 plugin.NS_CHAT_STATES,
57 )
50 stanza = parseXml(xml.encode("utf-8")) 58 stanza = parseXml(xml.encode("utf-8"))
51 self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]) 59 self.host.bridge.expectCall(
52 self.plugin.messageReceivedTrigger(self.host.getClient(Const.PROFILE[0]), stanza, None) 60 "chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0]
61 )
62 self.plugin.messageReceivedTrigger(
63 self.host.getClient(Const.PROFILE[0]), stanza, None
64 )
53 65
54 def test_messageSendTrigger(self): 66 def test_messageSendTrigger(self):
55 def cb(data): 67 def cb(data):
56 xml = data['xml'].toXml().encode("utf-8") 68 xml = data["xml"].toXml().encode("utf-8")
57 self.assertEqualXML(xml, expected.toXml().encode("utf-8")) 69 self.assertEqualXML(xml, expected.toXml().encode("utf-8"))
58 70
59 d_list = [] 71 d_list = []
60 72
61 for state in plugin.CHAT_STATES: 73 for state in plugin.CHAT_STATES:
62 mess_data = {"to": Const.JID[0], 74 mess_data = {
63 "type": "chat", 75 "to": Const.JID[0],
64 "message": "content", 76 "type": "chat",
65 "extra": {} if state == "active" else {"chat_state": state}} 77 "message": "content",
78 "extra": {} if state == "active" else {"chat_state": state},
79 }
66 stanza = u""" 80 stanza = u"""
67 <message type="chat" from="%s" to="%s" id="test_1"> 81 <message type="chat" from="%s" to="%s" id="test_1">
68 %s 82 %s
69 </message> 83 </message>
70 """ % (Const.JID_STR[1], Const.JID_STR[0], 84 """ % (
71 ("<body>%s</body>" % mess_data['message']) if state == "active" else "") 85 Const.JID_STR[1],
72 mess_data['xml'] = parseXml(stanza.encode("utf-8")) 86 Const.JID_STR[0],
73 expected = deepcopy(mess_data['xml']) 87 ("<body>%s</body>" % mess_data["message"]) if state == "active" else "",
88 )
89 mess_data["xml"] = parseXml(stanza.encode("utf-8"))
90 expected = deepcopy(mess_data["xml"])
74 expected.addElement(state, plugin.NS_CHAT_STATES) 91 expected.addElement(state, plugin.NS_CHAT_STATES)
75 post_treatments = defer.Deferred() 92 post_treatments = defer.Deferred()
76 self.plugin.messageSendTrigger(self.host.getClient(Const.PROFILE[0]), mess_data, None, post_treatments) 93 self.plugin.messageSendTrigger(
94 self.host.getClient(Const.PROFILE[0]), mess_data, None, post_treatments
95 )
77 96
78 post_treatments.addCallback(cb) 97 post_treatments.addCallback(cb)
79 post_treatments.callback(mess_data) 98 post_treatments.callback(mess_data)
80 d_list.append(post_treatments) 99 d_list.append(post_treatments)
81 100