diff options
author | Mark Haines <mark.haines@matrix.org> | 2015-02-11 11:37:30 +0000 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2015-02-11 11:37:30 +0000 |
commit | 896253e085751df88e747b29e638916b15cf7a0e (patch) | |
tree | ea62bdb8650946adfa6c9dc4603ce87a39e55e3e /tests/handlers | |
parent | Merge pull request #60 from matrix-org/single_source_version_and_dependencies (diff) | |
download | synapse-896253e085751df88e747b29e638916b15cf7a0e.tar.xz |
Factor out some of the common homeserver setup code into a
setup_test_homeserver function in utils.
Diffstat (limited to 'tests/handlers')
-rw-r--r-- | tests/handlers/test_directory.py | 14 | ||||
-rw-r--r-- | tests/handlers/test_federation.py | 11 | ||||
-rw-r--r-- | tests/handlers/test_presence.py | 16 | ||||
-rw-r--r-- | tests/handlers/test_presencelike.py | 39 | ||||
-rw-r--r-- | tests/handlers/test_profile.py | 29 | ||||
-rw-r--r-- | tests/handlers/test_room.py | 19 | ||||
-rw-r--r-- | tests/handlers/test_typing.py | 47 |
7 files changed, 60 insertions, 115 deletions
diff --git a/tests/handlers/test_directory.py b/tests/handlers/test_directory.py index 22119de46a..27306ba427 100644 --- a/tests/handlers/test_directory.py +++ b/tests/handlers/test_directory.py @@ -19,11 +19,10 @@ from twisted.internet import defer from mock import Mock -from synapse.server import HomeServer from synapse.handlers.directory import DirectoryHandler from synapse.types import RoomAlias -from tests.utils import SQLiteMemoryDbPool, MockKey +from tests.utils import setup_test_homeserver class DirectoryHandlers(object): @@ -46,19 +45,10 @@ class DirectoryTestCase(unittest.TestCase): self.query_handlers[query_type] = handler self.mock_federation.register_query_handler = register_query_handler - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - - hs = HomeServer( - "test", - db_pool=db_pool, + hs = yield setup_test_homeserver( http_client=None, resource_for_federation=Mock(), replication_layer=self.mock_federation, - config=self.mock_config, ) hs.handlers = DirectoryHandlers(hs) diff --git a/tests/handlers/test_federation.py b/tests/handlers/test_federation.py index 4270481139..c13ade3286 100644 --- a/tests/handlers/test_federation.py +++ b/tests/handlers/test_federation.py @@ -19,20 +19,17 @@ from tests import unittest from synapse.api.constants import EventTypes from synapse.events import FrozenEvent from synapse.handlers.federation import FederationHandler -from synapse.server import HomeServer from mock import NonCallableMock, ANY, Mock -from ..utils import MockKey +from ..utils import setup_test_homeserver class FederationTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - self.state_handler = NonCallableMock(spec_set=[ "compute_event_context", ]) @@ -43,9 +40,8 @@ class FederationTestCase(unittest.TestCase): ]) self.hostname = "test" - hs = HomeServer( + hs = yield setup_test_homeserver( self.hostname, - db_pool=None, datastore=NonCallableMock(spec_set=[ "persist_event", "store_room", @@ -61,7 +57,6 @@ class FederationTestCase(unittest.TestCase): "room_member_handler", "federation_handler", ]), - config=self.mock_config, auth=self.auth, state_handler=self.state_handler, keyring=Mock(), diff --git a/tests/handlers/test_presence.py b/tests/handlers/test_presence.py index 5621a8afaf..d88a977be4 100644 --- a/tests/handlers/test_presence.py +++ b/tests/handlers/test_presence.py @@ -21,11 +21,9 @@ from mock import Mock, call, ANY, NonCallableMock import json from tests.utils import ( - MockHttpResource, MockClock, DeferredMockCallable, SQLiteMemoryDbPool, - MockKey + MockHttpResource, MockClock, DeferredMockCallable, setup_test_homeserver ) -from synapse.server import HomeServer from synapse.api.constants import PresenceState from synapse.api.errors import SynapseError from synapse.handlers.presence import PresenceHandler, UserPresenceCache @@ -66,30 +64,20 @@ class PresenceTestCase(unittest.TestCase): def setUp(self): self.clock = MockClock() - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - self.mock_federation_resource = MockHttpResource() self.mock_http_client = Mock(spec=[]) self.mock_http_client.put_json = DeferredMockCallable() - db_pool = None hs_kwargs = {} - if hasattr(self, "make_datastore_mock"): hs_kwargs["datastore"] = self.make_datastore_mock() - else: - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - hs = HomeServer("test", + hs = yield setup_test_homeserver( clock=self.clock, - db_pool=db_pool, handlers=None, resource_for_federation=self.mock_federation_resource, http_client=self.mock_http_client, - config=self.mock_config, keyring=Mock(), **hs_kwargs ) diff --git a/tests/handlers/test_presencelike.py b/tests/handlers/test_presencelike.py index 3cdbb186ae..18cac9a846 100644 --- a/tests/handlers/test_presencelike.py +++ b/tests/handlers/test_presencelike.py @@ -21,9 +21,8 @@ from twisted.internet import defer from mock import Mock, call, ANY, NonCallableMock -from ..utils import MockClock, MockKey +from ..utils import MockClock, setup_test_homeserver -from synapse.server import HomeServer from synapse.api.constants import PresenceState from synapse.handlers.presence import PresenceHandler from synapse.handlers.profile import ProfileHandler @@ -57,29 +56,23 @@ class PresenceAndProfileHandlers(object): class PresenceProfilelikeDataTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - - hs = HomeServer("test", - clock=MockClock(), - db_pool=None, - datastore=Mock(spec=[ - "set_presence_state", - "is_presence_visible", - - "set_profile_displayname", - - "get_rooms_for_user_where_membership_is", - ]), - handlers=None, - resource_for_federation=Mock(), - http_client=None, - replication_layer=MockReplication(), - ratelimiter=NonCallableMock(spec_set=[ + hs = yield setup_test_homeserver( + clock=MockClock(), + datastore=Mock(spec=[ + "set_presence_state", + "is_presence_visible", + "set_profile_displayname", + "get_rooms_for_user_where_membership_is", + ]), + handlers=None, + resource_for_federation=Mock(), + http_client=None, + replication_layer=MockReplication(), + ratelimiter=NonCallableMock(spec_set=[ "send_message", - ]), - config=self.mock_config + ]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index 7b9590c110..31f03d73df 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -20,11 +20,10 @@ from twisted.internet import defer from mock import Mock, NonCallableMock from synapse.api.errors import AuthError -from synapse.server import HomeServer from synapse.handlers.profile import ProfileHandler from synapse.types import UserID -from tests.utils import SQLiteMemoryDbPool, MockKey +from tests.utils import setup_test_homeserver class ProfileHandlers(object): @@ -46,23 +45,15 @@ class ProfileTestCase(unittest.TestCase): self.query_handlers[query_type] = handler self.mock_federation.register_query_handler = register_query_handler - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - - hs = HomeServer("test", - db_pool=db_pool, - http_client=None, - handlers=None, - resource_for_federation=Mock(), - replication_layer=self.mock_federation, - config=self.mock_config, - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]) - ) + hs = yield setup_test_homeserver( + http_client=None, + handlers=None, + resource_for_federation=Mock(), + replication_layer=self.mock_federation, + ratelimiter=NonCallableMock(spec_set=[ + "send_message", + ]) + ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) diff --git a/tests/handlers/test_room.py b/tests/handlers/test_room.py index 9a23b3812d..6417f73309 100644 --- a/tests/handlers/test_room.py +++ b/tests/handlers/test_room.py @@ -20,23 +20,19 @@ from .. import unittest from synapse.api.constants import EventTypes, Membership from synapse.handlers.room import RoomMemberHandler, RoomCreationHandler from synapse.handlers.profile import ProfileHandler -from synapse.server import HomeServer from synapse.types import UserID -from ..utils import MockKey +from ..utils import setup_test_homeserver from mock import Mock, NonCallableMock class RoomMemberHandlerTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - self.hostname = "red" - hs = HomeServer( + hs = yield setup_test_homeserver( self.hostname, - db_pool=None, ratelimiter=NonCallableMock(spec_set=[ "send_message", ]), @@ -64,7 +60,6 @@ class RoomMemberHandlerTestCase(unittest.TestCase): "compute_event_context", "get_current_state", ]), - config=self.mock_config, ) self.federation = NonCallableMock(spec_set=[ @@ -319,15 +314,12 @@ class RoomMemberHandlerTestCase(unittest.TestCase): class RoomCreationTest(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): self.hostname = "red" - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - hs = HomeServer( + hs = yield setup_test_homeserver( self.hostname, - db_pool=None, datastore=NonCallableMock(spec_set=[ "store_room", "snapshot_room", @@ -344,7 +336,6 @@ class RoomCreationTest(unittest.TestCase): ratelimiter=NonCallableMock(spec_set=[ "send_message", ]), - config=self.mock_config, ) self.federation = NonCallableMock(spec_set=[ diff --git a/tests/handlers/test_typing.py b/tests/handlers/test_typing.py index 8a7fc028d1..bf34b7ccbd 100644 --- a/tests/handlers/test_typing.py +++ b/tests/handlers/test_typing.py @@ -20,10 +20,11 @@ from twisted.internet import defer from mock import Mock, call, ANY import json -from ..utils import MockHttpResource, MockClock, DeferredMockCallable, MockKey +from ..utils import ( + MockHttpResource, MockClock, DeferredMockCallable, setup_test_homeserver +) from synapse.api.errors import AuthError -from synapse.server import HomeServer from synapse.handlers.typing import TypingNotificationHandler from synapse.storage.transactions import DestinationsTable @@ -56,6 +57,7 @@ class JustTypingNotificationHandlers(object): class TypingNotificationsTestCase(unittest.TestCase): """Tests typing notifications to rooms.""" + @defer.inlineCallbacks def setUp(self): self.clock = MockClock() @@ -64,34 +66,29 @@ class TypingNotificationsTestCase(unittest.TestCase): self.mock_federation_resource = MockHttpResource() - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - mock_notifier = Mock(spec=["on_new_user_event"]) self.on_new_user_event = mock_notifier.on_new_user_event self.auth = Mock(spec=[]) - hs = HomeServer("test", - auth=self.auth, - clock=self.clock, - db_pool=None, - datastore=Mock(spec=[ - # Bits that Federation needs - "prep_send_transaction", - "delivered_txn", - "get_received_txn_response", - "set_received_txn_response", - "get_destination_retry_timings", - ]), - handlers=None, - notifier=mock_notifier, - resource_for_client=Mock(), - resource_for_federation=self.mock_federation_resource, - http_client=self.mock_http_client, - config=self.mock_config, - keyring=Mock(), - ) + hs = yield setup_test_homeserver( + auth=self.auth, + clock=self.clock, + datastore=Mock(spec=[ + # Bits that Federation needs + "prep_send_transaction", + "delivered_txn", + "get_received_txn_response", + "set_received_txn_response", + "get_destination_retry_timings", + ]), + handlers=None, + notifier=mock_notifier, + resource_for_client=Mock(), + resource_for_federation=self.mock_federation_resource, + http_client=self.mock_http_client, + keyring=Mock(), + ) hs.handlers = JustTypingNotificationHandlers(hs) self.handler = hs.get_handlers().typing_notification_handler |