diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 2255ea23e987..c5e9397b4562 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -259,8 +259,8 @@ async def is_interested_in_room( async def is_interested_in_event( self, event: EventBase, + store: "DataStore", cache_context: _CacheContext, - store: Optional["DataStore"] = None, ) -> bool: """Check if this service is interested in this event. @@ -288,10 +288,7 @@ async def is_interested_in_event( ): return True - # TODO: The store is only optional here to aid testing this function. We should - # instead convert the tests to use HomeServerTestCase in order to get a working - # database instance. - if store is not None and await self.is_interested_in_room( + if await self.is_interested_in_room( event.room_id, store, on_invalidate=cache_context.invalidate ): return True diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py index 61adafb0ebed..03fc73407f19 100644 --- a/synapse/handlers/appservice.py +++ b/synapse/handlers/appservice.py @@ -769,7 +769,7 @@ async def _get_services_for_event( # inside of a list comprehension anymore. interested_list = [] for s in services: - if await s.is_interested_in_event(event, store=self.store): + if await s.is_interested_in_event(event, self.store): interested_list.append(s) return interested_list diff --git a/tests/appservice/test_appservice.py b/tests/appservice/test_appservice.py index 38bbd8d11469..fb492216443b 100644 --- a/tests/appservice/test_appservice.py +++ b/tests/appservice/test_appservice.py @@ -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: @@ -39,6 +40,8 @@ def setUp(self): ) self.store = Mock() + self.store.get_aliases_for_room = simple_async_mock(return_value=[]) + self.store.get_users_in_room = simple_async_mock(return_value=[]) @defer.inlineCallbacks def test_regex_user_id_prefix_match(self): @@ -47,7 +50,7 @@ def test_regex_user_id_prefix_match(self): self.assertTrue( ( yield defer.ensureDeferred( - self.service.is_interested_in_event(self.event) + self.service.is_interested_in_event(self.event, self.store) ) ) ) @@ -59,7 +62,7 @@ def test_regex_user_id_prefix_no_match(self): self.assertFalse( ( yield defer.ensureDeferred( - self.service.is_interested_in_event(self.event) + self.service.is_interested_in_event(self.event, self.store) ) ) ) @@ -73,7 +76,7 @@ def test_regex_room_member_is_checked(self): self.assertTrue( ( yield defer.ensureDeferred( - self.service.is_interested_in_event(self.event) + self.service.is_interested_in_event(self.event, self.store) ) ) ) @@ -102,7 +105,7 @@ def test_regex_room_id_no_match(self): self.assertFalse( ( yield defer.ensureDeferred( - self.service.is_interested_in_event(self.event) + self.service.is_interested_in_event(self.event, self.store) ) ) ) @@ -207,7 +210,7 @@ def test_interested_in_self(self): self.assertTrue( ( yield defer.ensureDeferred( - self.service.is_interested_in_event(self.event) + self.service.is_interested_in_event(self.event, self.store) ) ) )