massive refactoring to switch from camelCase to snake_case:

historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.

However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.

To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.

This is a massive change, and may result in some bugs.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -44,7 +44,7 @@ class XEP_0033Test(helpers.SatTestCase):
self.host = helpers.FakeSAT()
self.plugin = plugin.XEP_0033(self.host)
def test_messageReceived(self):
def test_message_received(self):
self.host.memory.reinit()
xml = """
<message type="chat" from="%s" to="%s" id="test_1">
@ -64,8 +64,8 @@ class XEP_0033Test(helpers.SatTestCase):
)
stanza = parseXml(xml.encode("utf-8"))
treatments = defer.Deferred()
self.plugin.messageReceivedTrigger(
self.host.getClient(PROFILE), stanza, treatments
self.plugin.message_received_trigger(
self.host.get_client(PROFILE), stanza, treatments
)
data = {"extra": {}}
@ -98,7 +98,7 @@ class XEP_0033Test(helpers.SatTestCase):
mess_data["xml"] = parseXml(original_stanza.encode("utf-8"))
return mess_data
def _assertAddresses(self, mess_data):
def _assert_addresses(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"]
@ -113,13 +113,13 @@ class XEP_0033Test(helpers.SatTestCase):
)
addresses_element = parseXml(addresses_extra.encode("utf-8"))
expected.addChild(addresses_element)
self.assertEqualXML(
self.assert_equal_xml(
mess_data["xml"].toXml().encode("utf-8"), expected.toXml().encode("utf-8")
)
def _checkSentAndStored(self):
def _check_sent_and_stored(self):
"""Check that all the recipients got their messages and that the history has been filled.
/!\ see the comments in XEP_0033.sendAndStoreMessage"""
/!\ see the comments in XEP_0033.send_and_store_message"""
sent = []
stored = []
d_list = []
@ -135,23 +135,23 @@ class XEP_0033Test(helpers.SatTestCase):
else: # feature not supported, use normal behavior
sent.append(to_jid)
stored.append(to_jid)
helpers.unmuteLogging()
helpers.unmute_logging()
for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
to_jid = JID(to_s)
host = JID(to_jid.host)
helpers.muteLogging()
d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile=PROFILE)
helpers.mute_logging()
d = self.host.find_features_set([plugin.NS_ADDRESS], jid_=host, profile=PROFILE)
d.addCallback(cb, to_jid)
d_list.append(d)
def cb_list(__):
msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage"
msg = "/!\ see the comments in XEP_0033.send_and_store_message"
sent_recipients = [
JID(elt["to"]) for elt in self.host.getSentMessages(PROFILE_INDEX)
JID(elt["to"]) for elt in self.host.get_sent_messages(PROFILE_INDEX)
]
self.assertEqualUnsortedList(sent_recipients, sent, msg)
self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
self.assert_equal_unsorted_list(sent_recipients, sent, msg)
self.assert_equal_unsorted_list(self.host.stored_messages, stored, msg)
return defer.DeferredList(d_list).addCallback(cb_list)
@ -164,48 +164,48 @@ class XEP_0033Test(helpers.SatTestCase):
"""
pre_treatments = defer.Deferred()
post_treatments = defer.Deferred()
helpers.muteLogging()
helpers.mute_logging()
self.plugin.messageSendTrigger(
self.host.getClient[PROFILE], data, pre_treatments, post_treatments
self.host.get_client[PROFILE], data, pre_treatments, post_treatments
)
post_treatments.callback(data)
helpers.unmuteLogging()
helpers.unmute_logging()
post_treatments.addCallbacks(
self._assertAddresses, lambda failure: failure.trap(CancelError)
self._assert_addresses, lambda failure: failure.trap(CancelError)
)
return post_treatments
def test_messageSendTriggerFeatureNotSupported(self):
def test_message_send_trigger_feature_not_supported(self):
# feature is not supported, abort the message
self.host.memory.reinit()
data = self._get_mess_data()
return self._trigger(data)
def test_messageSendTriggerFeatureSupported(self):
def test_message_send_trigger_feature_supported(self):
# feature is supported by the main target server
self.host.reinit()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
data = self._get_mess_data()
d = self._trigger(data)
return d.addCallback(lambda __: self._checkSentAndStored())
return d.addCallback(lambda __: self._check_sent_and_stored())
def test_messageSendTriggerFeatureFullySupported(self):
def test_message_send_trigger_feature_fully_supported(self):
# feature is supported by all target servers
self.host.reinit()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
self.host.add_feature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
data = self._get_mess_data()
d = self._trigger(data)
return d.addCallback(lambda __: self._checkSentAndStored())
return d.addCallback(lambda __: self._check_sent_and_stored())
def test_messageSendTriggerFixWrongEntity(self):
def test_message_send_trigger_fix_wrong_entity(self):
# check that a wrong recipient entity is fixed by the backend
self.host.reinit()
self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
self.host.add_feature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
self.host.add_feature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
data = self._get_mess_data()
data["to"] = JID(JID_STR_X_TO)
d = self._trigger(data)
return d.addCallback(lambda __: self._checkSentAndStored())
return d.addCallback(lambda __: self._check_sent_and_stored())