diff sat/test/test_plugin_xep_0033.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
line wrap: on
line diff
--- a/sat/test/test_plugin_xep_0033.py	Wed Jun 27 07:51:29 2018 +0200
+++ b/sat/test/test_plugin_xep_0033.py	Wed Jun 27 20:14:46 2018 +0200
@@ -36,11 +36,10 @@
 JID_STR_X_CC = Const.JID_STR[1]
 JID_STR_X_BCC = Const.JID_STR[2]
 
-ADDRS = ('to', JID_STR_X_TO, 'cc', JID_STR_X_CC, 'bcc', JID_STR_X_BCC)
+ADDRS = ("to", JID_STR_X_TO, "cc", JID_STR_X_CC, "bcc", JID_STR_X_BCC)
 
 
 class XEP_0033Test(helpers.SatTestCase):
-
     def setUp(self):
         self.host = helpers.FakeSAT()
         self.plugin = plugin.XEP_0033(self.host)
@@ -56,48 +55,67 @@
                 <address type='bcc' jid='%s'/>
             </addresses>
         </message>
-        """ % (JID_STR_FROM, JID_STR_TO, JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC)
+        """ % (
+            JID_STR_FROM,
+            JID_STR_TO,
+            JID_STR_X_TO,
+            JID_STR_X_CC,
+            JID_STR_X_BCC,
+        )
         stanza = parseXml(xml.encode("utf-8"))
         treatments = defer.Deferred()
-        self.plugin.messageReceivedTrigger(self.host.getClient(PROFILE), stanza, treatments)
-        data = {'extra': {}}
+        self.plugin.messageReceivedTrigger(
+            self.host.getClient(PROFILE), stanza, treatments
+        )
+        data = {"extra": {}}
 
         def cb(data):
-            expected = ('to', JID_STR_X_TO, 'cc', JID_STR_X_CC, 'bcc', JID_STR_X_BCC)
-            msg = 'Expected: %s\nGot:      %s' % (expected, data['extra']['addresses'])
-            self.assertEqual(data['extra']['addresses'], '%s:%s\n%s:%s\n%s:%s\n' % expected, msg)
+            expected = ("to", JID_STR_X_TO, "cc", JID_STR_X_CC, "bcc", JID_STR_X_BCC)
+            msg = "Expected: %s\nGot:      %s" % (expected, data["extra"]["addresses"])
+            self.assertEqual(
+                data["extra"]["addresses"], "%s:%s\n%s:%s\n%s:%s\n" % expected, msg
+            )
 
         treatments.addCallback(cb)
         return treatments.callback(data)
 
     def _get_mess_data(self):
-        mess_data = {"to": JID(JID_STR_TO),
-                     "type": "chat",
-                     "message": "content",
-                     "extra": {}
-                     }
-        mess_data["extra"]["address"] = '%s:%s\n%s:%s\n%s:%s\n' % ADDRS
+        mess_data = {
+            "to": JID(JID_STR_TO),
+            "type": "chat",
+            "message": "content",
+            "extra": {},
+        }
+        mess_data["extra"]["address"] = "%s:%s\n%s:%s\n%s:%s\n" % ADDRS
         original_stanza = u"""
         <message type="chat" from="%s" to="%s" id="test_1">
             <body>content</body>
         </message>
-        """ % (JID_STR_FROM, JID_STR_TO)
-        mess_data['xml'] = parseXml(original_stanza.encode("utf-8"))
+        """ % (
+            JID_STR_FROM,
+            JID_STR_TO,
+        )
+        mess_data["xml"] = parseXml(original_stanza.encode("utf-8"))
         return mess_data
 
     def _assertAddresses(self, mess_data):
         """The mess_data that we got here has been modified by self.plugin.messageSendTrigger,
         check that the addresses element has been added to the stanza."""
-        expected = self._get_mess_data()['xml']
-        addresses_extra = """
+        expected = self._get_mess_data()["xml"]
+        addresses_extra = (
+            """
         <addresses xmlns='http://jabber.org/protocol/address'>
             <address type='%s' jid='%s'/>
             <address type='%s' jid='%s'/>
             <address type='%s' jid='%s'/>
-        </addresses>""" % ADDRS
-        addresses_element = parseXml(addresses_extra.encode('utf-8'))
+        </addresses>"""
+            % ADDRS
+        )
+        addresses_element = parseXml(addresses_extra.encode("utf-8"))
         expected.addChild(addresses_element)
-        self.assertEqualXML(mess_data['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8"))
+        self.assertEqualXML(
+            mess_data["xml"].toXml().encode("utf-8"), expected.toXml().encode("utf-8")
+        )
 
     def _checkSentAndStored(self):
         """Check that all the recipients got their messages and that the history has been filled.
@@ -108,7 +126,9 @@
 
         def cb(entities, to_jid):
             if host in entities:
-                if host not in sent:  # send the message to the entity offering the feature
+                if (
+                    host not in sent
+                ):  # send the message to the entity offering the feature
                     sent.append(host)
                     stored.append(host)
                 stored.append(to_jid)  # store in history for each recipient
@@ -127,7 +147,9 @@
 
         def cb_list(dummy):
             msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage"
-            sent_recipients = [JID(elt['to']) for elt in self.host.getSentMessages(PROFILE_INDEX)]
+            sent_recipients = [
+                JID(elt["to"]) for elt in self.host.getSentMessages(PROFILE_INDEX)
+            ]
             self.assertEqualUnsortedList(sent_recipients, sent, msg)
             self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
 
@@ -143,10 +165,14 @@
         pre_treatments = defer.Deferred()
         post_treatments = defer.Deferred()
         helpers.muteLogging()
-        self.plugin.messageSendTrigger(self.host.getClient[PROFILE], data, pre_treatments, post_treatments)
+        self.plugin.messageSendTrigger(
+            self.host.getClient[PROFILE], data, pre_treatments, post_treatments
+        )
         post_treatments.callback(data)
         helpers.unmuteLogging()
-        post_treatments.addCallbacks(self._assertAddresses, lambda failure: failure.trap(CancelError))
+        post_treatments.addCallbacks(
+            self._assertAddresses, lambda failure: failure.trap(CancelError)
+        )
         return post_treatments
 
     def test_messageSendTriggerFeatureNotSupported(self):