Unit-test DirectoryHandler against (real) SQLite memory store, not mocked storage layer

This commit is contained in:
Paul "LeoNerd" Evans 2014-09-11 11:59:48 +01:00
parent d83202b938
commit d13d0bba51
1 changed files with 12 additions and 15 deletions

View File

@ -25,6 +25,8 @@ from synapse.http.client import HttpClient
from synapse.handlers.directory import DirectoryHandler from synapse.handlers.directory import DirectoryHandler
from synapse.storage.directory import RoomAliasMapping from synapse.storage.directory import RoomAliasMapping
from tests.utils import SQLiteMemoryDbPool
logging.getLogger().addHandler(logging.NullHandler()) logging.getLogger().addHandler(logging.NullHandler())
@ -37,6 +39,7 @@ class DirectoryHandlers(object):
class DirectoryTestCase(unittest.TestCase): class DirectoryTestCase(unittest.TestCase):
""" Tests the directory service. """ """ Tests the directory service. """
@defer.inlineCallbacks
def setUp(self): def setUp(self):
self.mock_federation = Mock(spec=[ self.mock_federation = Mock(spec=[
"make_query", "make_query",
@ -48,32 +51,27 @@ class DirectoryTestCase(unittest.TestCase):
self.mock_federation.register_query_handler = register_query_handler self.mock_federation.register_query_handler = register_query_handler
hs = HomeServer("test", hs = HomeServer("test",
datastore=Mock(spec=[ db_pool=SQLiteMemoryDbPool(),
"get_association_from_room_alias",
"get_joined_hosts_for_room",
]),
http_client=None, http_client=None,
resource_for_federation=Mock(), resource_for_federation=Mock(),
replication_layer=self.mock_federation, replication_layer=self.mock_federation,
) )
hs.handlers = DirectoryHandlers(hs) hs.handlers = DirectoryHandlers(hs)
yield hs.get_db_pool().prepare()
self.handler = hs.get_handlers().directory_handler self.handler = hs.get_handlers().directory_handler
self.datastore = hs.get_datastore() self.store = hs.get_datastore()
def hosts(room_id):
return defer.succeed([])
self.datastore.get_joined_hosts_for_room.side_effect = hosts
self.my_room = hs.parse_roomalias("#my-room:test") self.my_room = hs.parse_roomalias("#my-room:test")
self.your_room = hs.parse_roomalias("#your-room:test")
self.remote_room = hs.parse_roomalias("#another:remote") self.remote_room = hs.parse_roomalias("#another:remote")
@defer.inlineCallbacks @defer.inlineCallbacks
def test_get_local_association(self): def test_get_local_association(self):
mocked_get = self.datastore.get_association_from_room_alias yield self.store.create_room_alias_association(
mocked_get.return_value = defer.succeed( self.my_room, "!8765qwer:test", ["test"]
RoomAliasMapping("!8765qwer:test", "#my-room:test", ["test"])
) )
result = yield self.handler.get_association(self.my_room) result = yield self.handler.get_association(self.my_room)
@ -106,9 +104,8 @@ class DirectoryTestCase(unittest.TestCase):
@defer.inlineCallbacks @defer.inlineCallbacks
def test_incoming_fed_query(self): def test_incoming_fed_query(self):
mocked_get = self.datastore.get_association_from_room_alias yield self.store.create_room_alias_association(
mocked_get.return_value = defer.succeed( self.your_room, "!8765asdf:test", ["test"]
RoomAliasMapping("!8765asdf:test", "#your-room:test", ["test"])
) )
response = yield self.query_handlers["directory"]( response = yield self.query_handlers["directory"](