Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Convert ApplicationServiceTestCase to use simple_async_mock #11880

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11880.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert `ApplicationServiceTestCase` to use `simple_async_mock`.
17 changes: 9 additions & 8 deletions tests/appservice/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from synapse.appservice import ApplicationService, Namespace

from tests import unittest
from tests.test_utils import simple_async_mock


def _regex(regex: str, exclusive: bool = True) -> Namespace:
Expand Down Expand Up @@ -91,10 +92,10 @@ def test_regex_alias_match(self):
self.service.namespaces[ApplicationService.NS_ALIASES].append(
_regex("#irc_.*:matrix.org")
)
self.store.get_aliases_for_room.return_value = defer.succeed(
self.store.get_aliases_for_room = simple_async_mock(
["#irc_foobar:matrix.org", "#athing:matrix.org"]
)
self.store.get_users_in_room.return_value = defer.succeed([])
self.store.get_users_in_room = simple_async_mock([])
self.assertTrue(
(
yield defer.ensureDeferred(
Expand Down Expand Up @@ -144,10 +145,10 @@ def test_regex_alias_no_match(self):
self.service.namespaces[ApplicationService.NS_ALIASES].append(
_regex("#irc_.*:matrix.org")
)
self.store.get_aliases_for_room.return_value = defer.succeed(
self.store.get_aliases_for_room = simple_async_mock(
["#xmpp_foobar:matrix.org", "#athing:matrix.org"]
)
self.store.get_users_in_room.return_value = defer.succeed([])
self.store.get_users_in_room = simple_async_mock([])
self.assertFalse(
(
yield defer.ensureDeferred(
Expand All @@ -163,10 +164,10 @@ def test_regex_multiple_matches(self):
)
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*"))
self.event.sender = "@irc_foobar:matrix.org"
self.store.get_aliases_for_room.return_value = defer.succeed(
self.store.get_aliases_for_room = simple_async_mock(
["#irc_barfoo:matrix.org"]
)
self.store.get_users_in_room.return_value = defer.succeed([])
self.store.get_users_in_room = simple_async_mock([])
self.assertTrue(
(
yield defer.ensureDeferred(
Expand All @@ -191,10 +192,10 @@ def test_interested_in_self(self):
def test_member_list_match(self):
self.service.namespaces[ApplicationService.NS_USERS].append(_regex("@irc_.*"))
# Note that @irc_fo:here is the AS user.
self.store.get_users_in_room.return_value = defer.succeed(
self.store.get_users_in_room = simple_async_mock(
["@alice:here", "@irc_fo:here", "@bob:here"]
)
self.store.get_aliases_for_room.return_value = defer.succeed([])
self.store.get_aliases_for_room = simple_async_mock([])

self.event.sender = "@xmpp_foobar:matrix.org"
self.assertTrue(
Expand Down