From db8c5cda1b6f546a841f047fdc8b5eb215a0874a Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Fri, 10 Dec 2021 20:18:20 +0000 Subject: [PATCH 1/3] Convert ApplicationServiceTestCase to use simple_async_mock --- tests/appservice/test_appservice.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tests/appservice/test_appservice.py b/tests/appservice/test_appservice.py index ba2a2bfd64ad..1c42c9bf901c 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: @@ -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( @@ -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( @@ -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( @@ -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( From 13bcb35314aa5bc50ac208ac1a3e6c1b903c8ba3 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 1 Feb 2022 16:11:07 +0000 Subject: [PATCH 2/3] changelog --- changelog.d/11880.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11880.misc diff --git a/changelog.d/11880.misc b/changelog.d/11880.misc new file mode 100644 index 000000000000..8125947b2a17 --- /dev/null +++ b/changelog.d/11880.misc @@ -0,0 +1 @@ +Convert `ApplicationServiceTestCase` to use `simple_async_mock`. \ No newline at end of file From 3cf98b0ed00ad79d4447b6437a1e3bb9aa58d6a4 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Tue, 1 Feb 2022 17:19:00 +0000 Subject: [PATCH 3/3] lint --- tests/appservice/test_appservice.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/appservice/test_appservice.py b/tests/appservice/test_appservice.py index 1c42c9bf901c..07d8105f41d6 100644 --- a/tests/appservice/test_appservice.py +++ b/tests/appservice/test_appservice.py @@ -164,9 +164,7 @@ 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 = simple_async_mock( - ["#irc_barfoo:matrix.org"] - ) + self.store.get_aliases_for_room = simple_async_mock(["#irc_barfoo:matrix.org"]) self.store.get_users_in_room = simple_async_mock([]) self.assertTrue( (