Mercurial > libervia-backend
diff tests/unit/test_pubsub-cache.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 | fe9cb52f4a9c |
children | 4b842c1fb686 |
line wrap: on
line diff
--- a/tests/unit/test_pubsub-cache.py Fri Apr 07 15:18:39 2023 +0200 +++ b/tests/unit/test_pubsub-cache.py Sat Apr 08 13:54:42 2023 +0200 @@ -27,22 +27,22 @@ @ed async def test_cache_is_used_transparently(self, host, client): - """Cache is used when a pubsub getItems operation is done""" + """Cache is used when a pubsub get_items operation is done""" items_ret = defer.Deferred() items_ret.callback(([], {})) client.pubsub_client.items = MagicMock(return_value=items_ret) - host.memory.storage.getPubsubNode.return_value = None - pubsub_node = host.memory.storage.setPubsubNode.return_value = PubsubNode( + host.memory.storage.get_pubsub_node.return_value = None + pubsub_node = host.memory.storage.set_pubsub_node.return_value = PubsubNode( sync_state = None ) - with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode: - await host.plugins["XEP-0060"].getItems( + with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node: + await host.plugins["XEP-0060"].get_items( client, None, "urn:xmpp:microblog:0", ) - assert cacheNode.call_count == 1 - assert cacheNode.call_args.args[-1] == pubsub_node + assert cache_node.call_count == 1 + assert cache_node.call_args.args[-1] == pubsub_node @ed async def test_cache_is_skipped_with_use_cache_false(self, host, client): @@ -50,18 +50,18 @@ items_ret = defer.Deferred() items_ret.callback(([], {})) client.pubsub_client.items = MagicMock(return_value=items_ret) - host.memory.storage.getPubsubNode.return_value = None - host.memory.storage.setPubsubNode.return_value = PubsubNode( + host.memory.storage.get_pubsub_node.return_value = None + host.memory.storage.set_pubsub_node.return_value = PubsubNode( sync_state = None ) - with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode: - await host.plugins["XEP-0060"].getItems( + with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node: + await host.plugins["XEP-0060"].get_items( client, None, "urn:xmpp:microblog:0", extra = {C.KEY_USE_CACHE: False} ) - assert not cacheNode.called + assert not cache_node.called @ed async def test_cache_is_not_used_when_no_cache(self, host, client): @@ -70,17 +70,17 @@ items_ret = defer.Deferred() items_ret.callback(([], {})) client.pubsub_client.items = MagicMock(return_value=items_ret) - host.memory.storage.getPubsubNode.return_value = None - host.memory.storage.setPubsubNode.return_value = PubsubNode( + host.memory.storage.get_pubsub_node.return_value = None + host.memory.storage.set_pubsub_node.return_value = PubsubNode( sync_state = None ) - with patch.object(host.plugins["PUBSUB_CACHE"], "cacheNode") as cacheNode: - await host.plugins["XEP-0060"].getItems( + with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node: + await host.plugins["XEP-0060"].get_items( client, None, "urn:xmpp:microblog:0", ) - assert not cacheNode.called + assert not cache_node.called @ed @@ -89,20 +89,20 @@ items_ret = defer.Deferred() items_ret.callback(([], {})) client.pubsub_client.items = MagicMock(return_value=items_ret) - host.memory.storage.getPubsubNode.return_value = PubsubNode( + host.memory.storage.get_pubsub_node.return_value = PubsubNode( sync_state = SyncState.COMPLETED ) with patch.object( host.plugins["PUBSUB_CACHE"], - "getItemsFromCache" - ) as getItemsFromCache: - getItemsFromCache.return_value = ([], {}) - await host.plugins["XEP-0060"].getItems( + "get_items_from_cache" + ) as get_items_from_cache: + get_items_from_cache.return_value = ([], {}) + await host.plugins["XEP-0060"].get_items( client, None, "urn:xmpp:microblog:0", ) - assert getItemsFromCache.call_count == 1 + assert get_items_from_cache.call_count == 1 assert not client.pubsub_client.items.called @ed @@ -111,21 +111,21 @@ items_ret = defer.Deferred() items_ret.callback(([], {})) client.pubsub_client.items = MagicMock(return_value=items_ret) - host.memory.storage.getPubsubNode.return_value = PubsubNode( + host.memory.storage.get_pubsub_node.return_value = PubsubNode( sync_state = SyncState.IN_PROGRESS ) - with patch.object(host.plugins["PUBSUB_CACHE"], "analyseNode") as analyseNode: - analyseNode.return_value = {"to_sync": True} + with patch.object(host.plugins["PUBSUB_CACHE"], "analyse_node") as analyse_node: + analyse_node.return_value = {"to_sync": True} with patch.object( host.plugins["PUBSUB_CACHE"], - "getItemsFromCache" - ) as getItemsFromCache: - getItemsFromCache.return_value = ([], {}) + "get_items_from_cache" + ) as get_items_from_cache: + get_items_from_cache.return_value = ([], {}) assert client.pubsub_client.items.call_count == 0 - await host.plugins["XEP-0060"].getItems( + await host.plugins["XEP-0060"].get_items( client, None, "urn:xmpp:microblog:0", ) - assert not getItemsFromCache.called + assert not get_items_from_cache.called assert client.pubsub_client.items.call_count == 1