0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-10 12:02:43 +01:00

Fix tests to support ratelimiting

This commit is contained in:
Mark Haines 2014-09-03 09:15:22 +01:00
parent 683596f91e
commit cdd8602e74
3 changed files with 64 additions and 2 deletions

View file

@ -39,6 +39,10 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
hs = HomeServer(
self.hostname,
db_pool=None,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
datastore=NonCallableMock(spec_set=[
"persist_event",
"get_joined_hosts_for_room",
@ -82,6 +86,8 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
self.snapshot = Mock()
self.datastore.snapshot_room.return_value = self.snapshot
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
@defer.inlineCallbacks
def test_invite(self):
@ -342,6 +348,10 @@ class RoomCreationTest(unittest.TestCase):
]),
auth=NonCallableMock(spec_set=["check"]),
state_handler=NonCallableMock(spec_set=["handle_new_event"]),
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.federation = NonCallableMock(spec_set=[
@ -368,6 +378,9 @@ class RoomCreationTest(unittest.TestCase):
return defer.succeed([])
self.datastore.get_joined_hosts_for_room.side_effect = hosts
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
@defer.inlineCallbacks
def test_room_creation(self):
user_id = "@foo:red"

View file

@ -32,7 +32,7 @@ import logging
from ..utils import MockHttpResource, MemoryDataStore
from .utils import RestTestCase
from mock import Mock
from mock import Mock, NonCallableMock
logging.getLogger().addHandler(logging.NullHandler())
@ -136,8 +136,15 @@ class EventStreamPermissionsTestCase(RestTestCase):
"call_later",
"cancel_call_later",
"time_msec",
"time"
]),
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()

View file

@ -30,7 +30,7 @@ import urllib
from ..utils import MockHttpResource, MemoryDataStore
from .utils import RestTestCase
from mock import Mock
from mock import Mock, NonCallableMock
PATH_PREFIX = "/_matrix/client/api/v1"
@ -58,7 +58,14 @@ class RoomPermissionsTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
def _get_user_by_token(token=None):
@ -405,7 +412,14 @@ class RoomsMemberListTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
self.auth_user_id = self.user_id
@ -483,7 +497,14 @@ class RoomsCreateTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
def _get_user_by_token(token=None):
@ -573,7 +594,14 @@ class RoomTopicTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
def _get_user_by_token(token=None):
@ -676,7 +704,14 @@ class RoomMemberStateTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
def _get_user_by_token(token=None):
@ -801,7 +836,14 @@ class RoomMessagesTestCase(RestTestCase):
replication_layer=Mock(),
state_handler=state_handler,
persistence_service=persistence_service,
ratelimiter=NonCallableMock(spec_set=[
"send_message",
]),
config=NonCallableMock(),
)
self.ratelimiter = hs.get_ratelimiter()
self.ratelimiter.send_message.return_value = (True, 0)
hs.get_handlers().federation_handler = Mock()
def _get_user_by_token(token=None):