tests (unit): fix tests + black reformatting.

This commit is contained in:
Goffi 2024-07-14 17:42:53 +02:00
commit 067d8f32bf

View file

@ -33,7 +33,7 @@ class TestPubsubCache:
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.get_pubsub_node.return_value = None
pubsub_node = host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
sync_state=None
)
with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node:
await host.plugins["XEP-0060"].get_items(
@ -51,15 +51,10 @@ class TestPubsubCache:
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.get_pubsub_node.return_value = None
host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
)
host.memory.storage.set_pubsub_node.return_value = PubsubNode(sync_state=None)
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}
client, None, "urn:xmpp:microblog:0", extra={C.KEY_USE_CACHE: False}
)
assert not cache_node.called
@ -71,9 +66,7 @@ class TestPubsubCache:
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.get_pubsub_node.return_value = None
host.memory.storage.set_pubsub_node.return_value = PubsubNode(
sync_state = None
)
host.memory.storage.set_pubsub_node.return_value = PubsubNode(sync_state=None)
with patch.object(host.plugins["PUBSUB_CACHE"], "cache_node") as cache_node:
await host.plugins["XEP-0060"].get_items(
client,
@ -82,7 +75,6 @@ class TestPubsubCache:
)
assert not cache_node.called
@ed
async def test_no_pubsub_get_when_cache_completed(self, host, client):
"""No pubsub get is emitted when items are fully cached"""
@ -90,11 +82,10 @@ class TestPubsubCache:
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.get_pubsub_node.return_value = PubsubNode(
sync_state = SyncState.COMPLETED
sync_state=SyncState.COMPLETED
)
with patch.object(
host.plugins["PUBSUB_CACHE"],
"get_items_from_cache"
host.plugins["PUBSUB_CACHE"], "get_items_from_cache"
) as get_items_from_cache:
get_items_from_cache.return_value = ([], {})
await host.plugins["XEP-0060"].get_items(
@ -112,13 +103,12 @@ class TestPubsubCache:
items_ret.callback(([], {}))
client.pubsub_client.items = MagicMock(return_value=items_ret)
host.memory.storage.get_pubsub_node.return_value = PubsubNode(
sync_state = SyncState.IN_PROGRESS
sync_state=SyncState.IN_PROGRESS
)
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"],
"get_items_from_cache"
host.plugins["PUBSUB_CACHE"], "get_items_from_cache"
) as get_items_from_cache:
get_items_from_cache.return_value = ([], {})
assert client.pubsub_client.items.call_count == 0