Mercurial > libervia-backend
comparison sat/test/test_plugin_xep_0334.py @ 4037:524856bd7b19
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
33 class XEP_0334Test(helpers.SatTestCase): | 33 class XEP_0334Test(helpers.SatTestCase): |
34 def setUp(self): | 34 def setUp(self): |
35 self.host = helpers.FakeSAT() | 35 self.host = helpers.FakeSAT() |
36 self.plugin = XEP_0334(self.host) | 36 self.plugin = XEP_0334(self.host) |
37 | 37 |
38 def test_messageSendTrigger(self): | 38 def test_message_send_trigger(self): |
39 template_xml = """ | 39 template_xml = """ |
40 <message | 40 <message |
41 from='romeo@montague.net/orchard' | 41 from='romeo@montague.net/orchard' |
42 to='juliet@capulet.com' | 42 to='juliet@capulet.com' |
43 type='chat'> | 43 type='chat'> |
49 | 49 |
50 d_list = [] | 50 d_list = [] |
51 | 51 |
52 def cb(data, expected_xml): | 52 def cb(data, expected_xml): |
53 result_xml = data["xml"].toXml().encode("utf-8") | 53 result_xml = data["xml"].toXml().encode("utf-8") |
54 self.assertEqualXML(result_xml, expected_xml, True) | 54 self.assert_equal_xml(result_xml, expected_xml, True) |
55 | 55 |
56 for key in HINTS + ("", "dummy_hint"): | 56 for key in HINTS + ("", "dummy_hint"): |
57 mess_data = { | 57 mess_data = { |
58 "xml": parseXml(original_xml.encode("utf-8")), | 58 "xml": parseXml(original_xml.encode("utf-8")), |
59 "extra": {key: True}, | 59 "extra": {key: True}, |
60 } | 60 } |
61 treatments = defer.Deferred() | 61 treatments = defer.Deferred() |
62 self.plugin.messageSendTrigger( | 62 self.plugin.messageSendTrigger( |
63 self.host.getClient(C.PROFILE[0]), mess_data, defer.Deferred(), treatments | 63 self.host.get_client(C.PROFILE[0]), mess_data, defer.Deferred(), treatments |
64 ) | 64 ) |
65 if treatments.callbacks: # the trigger added a callback | 65 if treatments.callbacks: # the trigger added a callback |
66 expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key) | 66 expected_xml = template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key) |
67 treatments.addCallback(cb, expected_xml) | 67 treatments.addCallback(cb, expected_xml) |
68 treatments.callback(mess_data) | 68 treatments.callback(mess_data) |
69 d_list.append(treatments) | 69 d_list.append(treatments) |
70 | 70 |
71 return defer.DeferredList(d_list) | 71 return defer.DeferredList(d_list) |
72 | 72 |
73 def test_messageReceivedTrigger(self): | 73 def test_message_received_trigger(self): |
74 template_xml = """ | 74 template_xml = """ |
75 <message | 75 <message |
76 from='romeo@montague.net/orchard' | 76 from='romeo@montague.net/orchard' |
77 to='juliet@capulet.com' | 77 to='juliet@capulet.com' |
78 type='chat'> | 78 type='chat'> |
90 d_list = [] | 90 d_list = [] |
91 | 91 |
92 for key in HINTS + ("dummy_hint",): | 92 for key in HINTS + ("dummy_hint",): |
93 message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)) | 93 message = parseXml(template_xml % ('<%s xmlns="urn:xmpp:hints"/>' % key)) |
94 post_treat = defer.Deferred() | 94 post_treat = defer.Deferred() |
95 self.plugin.messageReceivedTrigger( | 95 self.plugin.message_received_trigger( |
96 self.host.getClient(C.PROFILE[0]), message, post_treat | 96 self.host.get_client(C.PROFILE[0]), message, post_treat |
97 ) | 97 ) |
98 if post_treat.callbacks: | 98 if post_treat.callbacks: |
99 assert key in ("no-permanent-storage", "no-storage") | 99 assert key in ("no-permanent-storage", "no-storage") |
100 post_treat.addCallbacks(cb, eb) | 100 post_treat.addCallbacks(cb, eb) |
101 post_treat.callback(None) | 101 post_treat.callback(None) |