From 896253e085751df88e747b29e638916b15cf7a0e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 11 Feb 2015 11:37:30 +0000 Subject: Factor out some of the common homeserver setup code into a setup_test_homeserver function in utils. --- tests/rest/client/v1/test_events.py | 14 +---- tests/rest/client/v1/test_presence.py | 25 +++------ tests/rest/client/v1/test_profile.py | 13 ++--- tests/rest/client/v1/test_rooms.py | 97 +++++------------------------------ tests/rest/client/v1/test_typing.py | 13 +---- 5 files changed, 29 insertions(+), 133 deletions(-) (limited to 'tests/rest/client/v1') diff --git a/tests/rest/client/v1/test_events.py b/tests/rest/client/v1/test_events.py index 0384ffbb3d..f36340121d 100644 --- a/tests/rest/client/v1/test_events.py +++ b/tests/rest/client/v1/test_events.py @@ -23,9 +23,8 @@ import synapse.rest.client.v1.events import synapse.rest.client.v1.register import synapse.rest.client.v1.room -from synapse.server import HomeServer -from ....utils import MockHttpResource, SQLiteMemoryDbPool, MockKey +from ....utils import MockHttpResource, setup_test_homeserver from .utils import RestTestCase from mock import Mock, NonCallableMock @@ -113,15 +112,7 @@ class EventStreamPermissionsTestCase(RestTestCase): def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( - "test", - db_pool=db_pool, + hs = yield setup_test_homeserver( http_client=None, replication_layer=Mock(), clock=Mock(spec=[ @@ -133,7 +124,6 @@ class EventStreamPermissionsTestCase(RestTestCase): 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/rest/client/v1/test_presence.py b/tests/rest/client/v1/test_presence.py index f849120a3e..c1acba5a09 100644 --- a/tests/rest/client/v1/test_presence.py +++ b/tests/rest/client/v1/test_presence.py @@ -20,11 +20,10 @@ from twisted.internet import defer from mock import Mock -from ....utils import MockHttpResource, MockKey +from ....utils import MockHttpResource, setup_test_homeserver from synapse.api.constants import PresenceState from synapse.handlers.presence import PresenceHandler -from synapse.server import HomeServer from synapse.rest.client.v1 import presence from synapse.rest.client.v1 import events from synapse.types import UserID @@ -46,12 +45,10 @@ class JustPresenceHandlers(object): class PresenceStateTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - hs = HomeServer("test", - db_pool=None, + hs = yield setup_test_homeserver( datastore=Mock(spec=[ "get_presence_state", "set_presence_state", @@ -60,7 +57,6 @@ class PresenceStateTestCase(unittest.TestCase): http_client=None, resource_for_client=self.mock_resource, resource_for_federation=self.mock_resource, - config=self.mock_config, ) hs.handlers = JustPresenceHandlers(hs) @@ -128,13 +124,11 @@ class PresenceStateTestCase(unittest.TestCase): class PresenceListTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - hs = HomeServer("test", - db_pool=None, + hs = yield setup_test_homeserver( datastore=Mock(spec=[ "has_presence_state", "get_presence_state", @@ -149,7 +143,6 @@ class PresenceListTestCase(unittest.TestCase): http_client=None, resource_for_client=self.mock_resource, resource_for_federation=self.mock_resource, - config=self.mock_config, ) hs.handlers = JustPresenceHandlers(hs) @@ -242,12 +235,10 @@ class PresenceListTestCase(unittest.TestCase): class PresenceEventStreamTestCase(unittest.TestCase): + @defer.inlineCallbacks def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = Mock() - self.mock_config.signing_key = [MockKey()] - # HIDEOUS HACKERY # TODO(paul): This should be injected in via the HomeServer DI system from synapse.streams.events import ( @@ -264,8 +255,7 @@ class PresenceEventStreamTestCase(unittest.TestCase): } EventSources.SOURCE_TYPES["presence"] = PresenceEventSource - hs = HomeServer("test", - db_pool=None, + hs = yield setup_test_homeserver( http_client=None, resource_for_client=self.mock_resource, resource_for_federation=self.mock_resource, @@ -278,7 +268,6 @@ class PresenceEventStreamTestCase(unittest.TestCase): "cancel_call_later", "time_msec", ]), - config=self.mock_config, ) hs.get_clock().time_msec.return_value = 1000000 diff --git a/tests/rest/client/v1/test_profile.py b/tests/rest/client/v1/test_profile.py index 6a2085276a..5cd5767f2e 100644 --- a/tests/rest/client/v1/test_profile.py +++ b/tests/rest/client/v1/test_profile.py @@ -20,10 +20,9 @@ from twisted.internet import defer from mock import Mock, NonCallableMock -from ....utils import MockHttpResource, MockKey +from ....utils import MockHttpResource, setup_test_homeserver from synapse.api.errors import SynapseError, AuthError -from synapse.server import HomeServer from synapse.types import UserID from synapse.rest.client.v1 import profile @@ -35,6 +34,7 @@ PATH_PREFIX = "/_matrix/client/api/v1" class ProfileTestCase(unittest.TestCase): """ Tests profile management. """ + @defer.inlineCallbacks def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.mock_handler = Mock(spec=[ @@ -44,17 +44,12 @@ class ProfileTestCase(unittest.TestCase): "set_avatar_url", ]) - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - hs = HomeServer("test", - db_pool=None, + hs = yield setup_test_homeserver( + "test", http_client=None, resource_for_client=self.mock_resource, federation=Mock(), replication_layer=Mock(), - datastore=None, - config=self.mock_config, ) def _get_user_by_req(request=None): diff --git a/tests/rest/client/v1/test_rooms.py b/tests/rest/client/v1/test_rooms.py index 81ead10e76..72fb4576b1 100644 --- a/tests/rest/client/v1/test_rooms.py +++ b/tests/rest/client/v1/test_rooms.py @@ -21,13 +21,12 @@ from twisted.internet import defer import synapse.rest.client.v1.room from synapse.api.constants import Membership -from synapse.server import HomeServer from synapse.types import UserID import json import urllib -from ....utils import MockHttpResource, SQLiteMemoryDbPool, MockKey +from ....utils import MockHttpResource, setup_test_homeserver from .utils import RestTestCase from mock import Mock, NonCallableMock @@ -44,21 +43,11 @@ class RoomPermissionsTestCase(RestTestCase): def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -439,21 +428,11 @@ class RoomsMemberListTestCase(RestTestCase): def setUp(self): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -531,21 +510,11 @@ class RoomsCreateTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -634,21 +603,11 @@ class RoomTopicTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -751,21 +710,11 @@ class RoomMemberStateTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -888,21 +837,11 @@ class RoomMessagesTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), - ratelimiter=NonCallableMock(spec_set=[ - "send_message", - ]), - config=self.mock_config, + ratelimiter=NonCallableMock(spec_set=["send_message"]), ) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) @@ -993,21 +932,13 @@ class RoomInitialSyncTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", - db_pool=db_pool, http_client=None, replication_layer=Mock(), 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/rest/client/v1/test_typing.py b/tests/rest/client/v1/test_typing.py index c5d5b06da3..80f2ec9ddf 100644 --- a/tests/rest/client/v1/test_typing.py +++ b/tests/rest/client/v1/test_typing.py @@ -19,10 +19,9 @@ from twisted.internet import defer import synapse.rest.client.v1.room -from synapse.server import HomeServer from synapse.types import UserID -from ....utils import MockHttpResource, MockClock, SQLiteMemoryDbPool, MockKey +from ....utils import MockHttpResource, MockClock, setup_test_homeserver from .utils import RestTestCase from mock import Mock, NonCallableMock @@ -42,22 +41,14 @@ class RoomTypingTestCase(RestTestCase): self.mock_resource = MockHttpResource(prefix=PATH_PREFIX) self.auth_user_id = self.user_id - self.mock_config = NonCallableMock() - self.mock_config.signing_key = [MockKey()] - - db_pool = SQLiteMemoryDbPool() - yield db_pool.prepare() - - hs = HomeServer( + hs = yield setup_test_homeserver( "red", clock=self.clock, - db_pool=db_pool, http_client=None, replication_layer=Mock(), ratelimiter=NonCallableMock(spec_set=[ "send_message", ]), - config=self.mock_config, ) self.hs = hs -- cgit 1.4.1