Convert the directory handler tests to use HomeserverTestCase (#6919)

Convert directory handler tests to use HomeserverTestCase.
pull/6921/head
Patrick Cloke 2020-02-14 09:05:43 -05:00 committed by GitHub
parent 49f877d32e
commit 02e89021f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 24 deletions

1
changelog.d/6919.misc Normal file
View File

@ -0,0 +1 @@
Convert the directory handler tests to use HomeserverTestCase.

View File

@ -19,24 +19,16 @@ from mock import Mock
from twisted.internet import defer from twisted.internet import defer
from synapse.config.room_directory import RoomDirectoryConfig from synapse.config.room_directory import RoomDirectoryConfig
from synapse.handlers.directory import DirectoryHandler
from synapse.rest.client.v1 import directory, room from synapse.rest.client.v1 import directory, room
from synapse.types import RoomAlias from synapse.types import RoomAlias
from tests import unittest from tests import unittest
from tests.utils import setup_test_homeserver
class DirectoryHandlers(object): class DirectoryTestCase(unittest.HomeserverTestCase):
def __init__(self, hs):
self.directory_handler = DirectoryHandler(hs)
class DirectoryTestCase(unittest.TestCase):
""" Tests the directory service. """ """ Tests the directory service. """
@defer.inlineCallbacks def make_homeserver(self, reactor, clock):
def setUp(self):
self.mock_federation = Mock() self.mock_federation = Mock()
self.mock_registry = Mock() self.mock_registry = Mock()
@ -47,14 +39,12 @@ class DirectoryTestCase(unittest.TestCase):
self.mock_registry.register_query_handler = register_query_handler self.mock_registry.register_query_handler = register_query_handler
hs = yield setup_test_homeserver( hs = self.setup_test_homeserver(
self.addCleanup,
http_client=None, http_client=None,
resource_for_federation=Mock(), resource_for_federation=Mock(),
federation_client=self.mock_federation, federation_client=self.mock_federation,
federation_registry=self.mock_registry, federation_registry=self.mock_registry,
) )
hs.handlers = DirectoryHandlers(hs)
self.handler = hs.get_handlers().directory_handler self.handler = hs.get_handlers().directory_handler
@ -64,23 +54,25 @@ class DirectoryTestCase(unittest.TestCase):
self.your_room = RoomAlias.from_string("#your-room:test") self.your_room = RoomAlias.from_string("#your-room:test")
self.remote_room = RoomAlias.from_string("#another:remote") self.remote_room = RoomAlias.from_string("#another:remote")
@defer.inlineCallbacks return hs
def test_get_local_association(self): def test_get_local_association(self):
yield self.store.create_room_alias_association( self.get_success(
self.store.create_room_alias_association(
self.my_room, "!8765qwer:test", ["test"] self.my_room, "!8765qwer:test", ["test"]
) )
)
result = yield self.handler.get_association(self.my_room) result = self.get_success(self.handler.get_association(self.my_room))
self.assertEquals({"room_id": "!8765qwer:test", "servers": ["test"]}, result) self.assertEquals({"room_id": "!8765qwer:test", "servers": ["test"]}, result)
@defer.inlineCallbacks
def test_get_remote_association(self): def test_get_remote_association(self):
self.mock_federation.make_query.return_value = defer.succeed( self.mock_federation.make_query.return_value = defer.succeed(
{"room_id": "!8765qwer:test", "servers": ["test", "remote"]} {"room_id": "!8765qwer:test", "servers": ["test", "remote"]}
) )
result = yield self.handler.get_association(self.remote_room) result = self.get_success(self.handler.get_association(self.remote_room))
self.assertEquals( self.assertEquals(
{"room_id": "!8765qwer:test", "servers": ["test", "remote"]}, result {"room_id": "!8765qwer:test", "servers": ["test", "remote"]}, result
@ -93,14 +85,15 @@ class DirectoryTestCase(unittest.TestCase):
ignore_backoff=True, ignore_backoff=True,
) )
@defer.inlineCallbacks
def test_incoming_fed_query(self): def test_incoming_fed_query(self):
yield self.store.create_room_alias_association( self.get_success(
self.store.create_room_alias_association(
self.your_room, "!8765asdf:test", ["test"] self.your_room, "!8765asdf:test", ["test"]
) )
)
response = yield self.query_handlers["directory"]( response = self.get_success(
{"room_alias": "#your-room:test"} self.handler.on_directory_query({"room_alias": "#your-room:test"})
) )
self.assertEquals({"room_id": "!8765asdf:test", "servers": ["test"]}, response) self.assertEquals({"room_id": "!8765asdf:test", "servers": ["test"]}, response)