From c145c810f222d3dd3873eff7801c0925a315417e Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 4 Jun 2020 11:54:42 -0400 Subject: [PATCH] Back out some changes. --- tests/handlers/test_profile.py | 14 ++------------ tests/replication/slave/storage/_base.py | 17 ++++------------- tests/rest/client/v1/test_events.py | 15 +++------------ tests/rest/client/v1/test_rooms.py | 18 +++++------------- tests/rest/client/v1/test_typing.py | 18 +++++------------- 5 files changed, 19 insertions(+), 63 deletions(-) diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index cf9026d3a79f..5898f39c7a0f 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -14,13 +14,12 @@ # limitations under the License. -from mock import Mock, patch +from mock import Mock, NonCallableMock from twisted.internet import defer import synapse.types from synapse.api.errors import AuthError, SynapseError -from synapse.api.ratelimiting import Ratelimiter from synapse.handlers.profile import MasterProfileHandler from synapse.types import UserID @@ -56,16 +55,7 @@ def register_query_handler(query_type, handler): federation_client=self.mock_federation, federation_server=Mock(), federation_registry=self.mock_registry, - ) - - # Patch Ratelimiter to allow all requests - patch.object( - Ratelimiter, - "can_do_action", - new_callable=lambda *args, **kwargs: (True, 0.0), - ) - patch.object( - Ratelimiter, "ratelimit", new_callable=lambda *args, **kwargs: None + ratelimiter=NonCallableMock(spec_set=["can_do_action"]), ) self.store = hs.get_datastore() diff --git a/tests/replication/slave/storage/_base.py b/tests/replication/slave/storage/_base.py index f3e0af6460f0..59f109781d33 100644 --- a/tests/replication/slave/storage/_base.py +++ b/tests/replication/slave/storage/_base.py @@ -13,9 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mock import Mock, patch - -from synapse.api.ratelimiting import Ratelimiter +from mock import Mock, NonCallableMock from tests.replication._base import BaseStreamTestCase @@ -23,16 +21,9 @@ class BaseSlavedStoreTestCase(BaseStreamTestCase): def make_homeserver(self, reactor, clock): - hs = self.setup_test_homeserver(federation_client=Mock(),) - - # Patch Ratelimiter to allow all requests - patch.object( - Ratelimiter, - "can_do_action", - new_callable=lambda *args, **kwargs: (True, 0.0), - ) - patch.object( - Ratelimiter, "ratelimit", new_callable=lambda *args, **kwargs: None + hs = self.setup_test_homeserver( + federation_client=Mock(), + ratelimiter=NonCallableMock(spec_set=["can_do_action"]), ) return hs diff --git a/tests/rest/client/v1/test_events.py b/tests/rest/client/v1/test_events.py index 95dd24fa5c27..dcad433bef76 100644 --- a/tests/rest/client/v1/test_events.py +++ b/tests/rest/client/v1/test_events.py @@ -15,10 +15,9 @@ """ Tests REST events for /events paths.""" -from mock import Mock, patch +from mock import Mock, NonCallableMock import synapse.rest.admin -from synapse.api.ratelimiting import Ratelimiter from synapse.rest.client.v1 import events, login, room from tests import unittest @@ -41,16 +40,8 @@ def make_homeserver(self, reactor, clock): config["enable_registration"] = True config["auto_join_rooms"] = [] - hs = self.setup_test_homeserver(config=config,) - - # Patch Ratelimiter to allow all requests - patch.object( - Ratelimiter, - "can_do_action", - new_callable=lambda *args, **kwargs: (True, 0.0), - ) - patch.object( - Ratelimiter, "ratelimit", new_callable=lambda *args, **kwargs: None + hs = self.setup_test_homeserver( + config=config, ratelimiter=NonCallableMock(spec_set=["can_do_action"]) ) hs.get_handlers().federation_handler = Mock() diff --git a/tests/rest/client/v1/test_rooms.py b/tests/rest/client/v1/test_rooms.py index af2617d7e391..1ec600be686f 100644 --- a/tests/rest/client/v1/test_rooms.py +++ b/tests/rest/client/v1/test_rooms.py @@ -20,14 +20,13 @@ import json -from mock import Mock, patch +from mock import Mock, NonCallableMock from six.moves.urllib import parse as urlparse from twisted.internet import defer import synapse.rest.admin from synapse.api.constants import EventContentFields, EventTypes, Membership -from synapse.api.ratelimiting import Ratelimiter from synapse.handlers.pagination import PurgeStatus from synapse.rest.client.v1 import directory, login, profile, room from synapse.rest.client.v2_alpha import account @@ -47,17 +46,10 @@ class RoomBase(unittest.HomeserverTestCase): def make_homeserver(self, reactor, clock): self.hs = self.setup_test_homeserver( - "red", http_client=None, federation_client=Mock(), - ) - - # Patch Ratelimiter to allow all requests - patch.object( - Ratelimiter, - "can_do_action", - new_callable=lambda *args, **kwargs: (True, 0.0), - ) - patch.object( - Ratelimiter, "ratelimit", new_callable=lambda *args, **kwargs: None + "red", + http_client=None, + federation_client=Mock(), + ratelimiter=NonCallableMock(spec_set=["can_do_action"]), ) self.hs.get_federation_handler = Mock(return_value=Mock()) diff --git a/tests/rest/client/v1/test_typing.py b/tests/rest/client/v1/test_typing.py index 4d9f882bf1d1..f46a207a6f92 100644 --- a/tests/rest/client/v1/test_typing.py +++ b/tests/rest/client/v1/test_typing.py @@ -16,11 +16,10 @@ """Tests REST events for /rooms paths.""" -from mock import Mock, patch +from mock import Mock, NonCallableMock from twisted.internet import defer -from synapse.api.ratelimiting import Ratelimiter from synapse.rest.client.v1 import room from synapse.types import UserID @@ -40,17 +39,10 @@ class RoomTypingTestCase(unittest.HomeserverTestCase): def make_homeserver(self, reactor, clock): hs = self.setup_test_homeserver( - "red", http_client=None, federation_client=Mock(), - ) - - # Patch Ratelimiter to allow all requests - patch.object( - Ratelimiter, - "can_do_action", - new_callable=lambda *args, **kwargs: (True, 0.0), - ) - patch.object( - Ratelimiter, "ratelimit", new_callable=lambda *args, **kwargs: None + "red", + http_client=None, + federation_client=Mock(), + ratelimiter=NonCallableMock(spec_set=["can_do_action"]), ) self.event_source = hs.get_event_sources().sources["typing"]