diff options
author | Neil Johnson <neil@fragile.org.uk> | 2018-11-13 23:12:58 +0000 |
---|---|---|
committer | Neil Johnson <neil@fragile.org.uk> | 2018-11-13 23:12:58 +0000 |
commit | b01271a12be164d5f8286aa3c3106a32c6ac6be3 (patch) | |
tree | 9eb3a69566a1fba08c3a707d7ee35c94410bfb23 | |
parent | fix unit tests (diff) | |
download | synapse-b01271a12be164d5f8286aa3c3106a32c6ac6be3.tar.xz |
tweak tests and tidy
-rw-r--r-- | synapse/handlers/register.py | 2 | ||||
-rw-r--r-- | synapse/handlers/user_directory.py | 2 | ||||
-rw-r--r-- | synapse/storage/user_directory.py | 10 | ||||
-rw-r--r-- | tests/handlers/test_register.py | 34 | ||||
-rw-r--r-- | tests/storage/test_registration.py | 3 | ||||
-rw-r--r-- | tests/storage/test_user_directory.py | 3 |
6 files changed, 18 insertions, 36 deletions
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 70fd191717..ceab38f18c 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -230,11 +230,9 @@ class RegistrationHandler(BaseHandler): # the room is never created, though this seems unlikely and # recoverable from given the support user being involved in the first # place. - if (self.hs.config.autocreate_auto_join_rooms and not is_support): count = yield self.store.count_all_users() should_auto_create_rooms = count == 1 - for r in self.hs.config.auto_join_rooms: try: if should_auto_create_rooms: diff --git a/synapse/handlers/user_directory.py b/synapse/handlers/user_directory.py index 1e233e044f..821058cfcb 100644 --- a/synapse/handlers/user_directory.py +++ b/synapse/handlers/user_directory.py @@ -332,8 +332,6 @@ class UserDirectoryHandler(object): public_value=Membership.JOIN, ) - - if not change: # Need to check if the server left the room entirely, if so # we might need to remove all the users in that room diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py index b8f3bfdc97..4fbfe8d90c 100644 --- a/synapse/storage/user_directory.py +++ b/synapse/storage/user_directory.py @@ -16,11 +16,11 @@ import logging import re -from six import iteritems, iterkeys +from six import iteritems from twisted.internet import defer -from synapse.api.constants import EventTypes, JoinRules, UserTypes +from synapse.api.constants import EventTypes, JoinRules from synapse.storage.engines import PostgresEngine, Sqlite3Engine from synapse.types import get_domain_from_id, get_localpart_from_id from synapse.util.caches.descriptors import cached, cachedInlineCallbacks @@ -31,9 +31,6 @@ logger = logging.getLogger(__name__) class UserDirectoryStore(SQLBaseStore): - def __init__(self, dbconn, hs): - super(UserDirectoryStore, self).__init__(dbconn, hs) - self.store = hs.get_datastore() @cachedInlineCallbacks(cache_context=True) def is_room_world_readable_or_publicly_joinable(self, room_id, cache_context): @@ -68,7 +65,6 @@ class UserDirectoryStore(SQLBaseStore): or publically joinable user_ids (list(str)): Users to add """ - yield self._simple_insert_many( table="users_in_public_rooms", values=[ @@ -83,7 +79,6 @@ class UserDirectoryStore(SQLBaseStore): for user_id in user_ids: self.get_user_in_public_room.invalidate((user_id,)) - def add_profiles_to_user_dir(self, room_id, users_with_profile): """Add profiles to the user directory @@ -92,7 +87,6 @@ class UserDirectoryStore(SQLBaseStore): users_with_profile (dict): Users to add to directory in the form of mapping of user_id -> ProfileInfo """ - if isinstance(self.database_engine, PostgresEngine): # We weight the loclpart most highly, then display name and finally # server name diff --git a/tests/handlers/test_register.py b/tests/handlers/test_register.py index d0512f599c..dc297c030b 100644 --- a/tests/handlers/test_register.py +++ b/tests/handlers/test_register.py @@ -17,7 +17,7 @@ from mock import Mock from twisted.internet import defer -from synapse.api.errors import ResourceLimitError +from synapse.api.errors import ResourceLimitError, SynapseError from synapse.handlers.register import RegistrationHandler from synapse.types import RoomAlias, UserID, create_requester @@ -181,22 +181,16 @@ class RegistrationTestCase(unittest.TestCase): rooms = yield self.store.get_rooms_for_user(res[0]) self.assertEqual(len(rooms), 0) - # @defer.inlineCallbacks - # def test_auto_create_auto_join_rooms_when_support_user_exists(self): - # room_alias_str = "#room:test" - # self.hs.config.auto_join_rooms = [room_alias_str] - # - # res_support = yield self.handler.register(localpart='support', - # user_type=UserTypes.SUPPORT) - # rooms = yield self.store.get_rooms_for_user(res_support[0]) - # self.assertTrue(len(rooms) == 0) - # - # res = yield self.handler.register(localpart='jeff') - # - # rooms = yield self.store.get_rooms_for_user(res[0]) - # directory_handler = self.hs.get_handlers().directory_handler - # room_alias = RoomAlias.from_string(room_alias_str) - # room_id = yield directory_handler.get_association(room_alias) - # - # self.assertTrue(room_id['room_id'] in rooms) - # self.assertEqual(len(rooms), 1) + @defer.inlineCallbacks + def test_auto_create_auto_join_rooms_when_support_user_exists(self): + room_alias_str = "#room:test" + self.hs.config.auto_join_rooms = [room_alias_str] + + self.store.is_support_user = Mock(return_value=True) + res = yield self.handler.register(localpart='support') + rooms = yield self.store.get_rooms_for_user(res[0]) + self.assertEqual(len(rooms), 0) + directory_handler = self.hs.get_handlers().directory_handler + room_alias = RoomAlias.from_string(room_alias_str) + with self.assertRaises(SynapseError): + yield directory_handler.get_association(room_alias) diff --git a/tests/storage/test_registration.py b/tests/storage/test_registration.py index c16b8b6ea4..421713cb32 100644 --- a/tests/storage/test_registration.py +++ b/tests/storage/test_registration.py @@ -16,9 +16,10 @@ from twisted.internet import defer +from synapse.api.constants import UserTypes + from tests import unittest from tests.utils import setup_test_homeserver -from synapse.api.constants import UserTypes class RegistrationStoreTestCase(unittest.TestCase): diff --git a/tests/storage/test_user_directory.py b/tests/storage/test_user_directory.py index 04cfa8c691..eff62e42e4 100644 --- a/tests/storage/test_user_directory.py +++ b/tests/storage/test_user_directory.py @@ -15,8 +15,6 @@ from twisted.internet import defer -from synapse.api.constants import UserTypes -from synapse.storage import UserDirectoryStore from synapse.storage.roommember import ProfileInfo from tests import unittest @@ -33,7 +31,6 @@ class UserDirectoryStoreTestCase(unittest.TestCase): def setUp(self): self.hs = yield setup_test_homeserver(self.addCleanup) self.store = self.hs.get_datastore() - # self.store = UserDirectoryStore(self.hs.get_db_conn(), self.hs) # alice and bob are both in !room_id. bobby is not but shares # a homeserver with alice. |