def setUp(self): self.mock_federation = Mock(spec=[ "make_query", ]) self.query_handlers = {} def register_query_handler(query_type, handler): self.query_handlers[query_type] = handler self.mock_federation.register_query_handler = register_query_handler db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, http_client=None, handlers=None, resource_for_federation=Mock(), replication_layer=self.mock_federation, ) hs.handlers = ProfileHandlers(hs) self.store = hs.get_datastore() self.frank = hs.parse_userid("@1234ABCD:test") self.bob = hs.parse_userid("@4567:test") self.alice = hs.parse_userid("@alice:remote") yield self.store.create_profile(self.frank.localpart) self.handler = hs.get_handlers().profile_handler # TODO(paul): Icky signal declarings.. booo hs.get_distributor().declare("changed_presencelike_data")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() self.mock_config = Mock() self.mock_config.signing_key = [MockKey()] hs = HomeServer( "test", db_pool=db_pool, config=self.mock_config, resource_for_federation=Mock(), http_client=None, ) self.store = hs.get_datastore() self.event_builder_factory = hs.get_event_builder_factory() self.handlers = hs.get_handlers() self.message_handler = self.handlers.message_handler self.u_alice = hs.parse_userid("@alice:test") self.u_bob = hs.parse_userid("@bob:test") self.room1 = hs.parse_roomid("!abc123:test") self.room2 = hs.parse_roomid("!xyx987:test") self.depth = 1
def setUp(self): self.mock_federation = Mock(spec=[ "make_query", ]) self.query_handlers = {} def register_query_handler(query_type, handler): 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, resource_for_federation=Mock(), replication_layer=self.mock_federation, config=self.mock_config, ) hs.handlers = DirectoryHandlers(hs) self.handler = hs.get_handlers().directory_handler self.store = hs.get_datastore() 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")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() self.mock_config = Mock() self.mock_config.signing_key = [MockKey()] hs = HomeServer( "test", db_pool=db_pool, config=self.mock_config, resource_for_federation=Mock(), http_client=None, ) # We can't test the RoomMemberStore on its own without the other event # storage logic self.store = hs.get_datastore() self.event_builder_factory = hs.get_event_builder_factory() self.handlers = hs.get_handlers() self.message_handler = self.handlers.message_handler self.u_alice = hs.parse_userid("@alice:test") self.u_bob = hs.parse_userid("@bob:test") # User elsewhere on another host self.u_charlie = hs.parse_userid("@charlie:elsewhere") self.room = hs.parse_roomid("!abc123:test")
def setUp(self): self.mock_federation = Mock(spec=[ "make_query", ]) self.query_handlers = {} def register_query_handler(query_type, handler): self.query_handlers[query_type] = handler self.mock_federation.register_query_handler = register_query_handler db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, http_client=None, resource_for_federation=Mock(), replication_layer=self.mock_federation, ) hs.handlers = DirectoryHandlers(hs) self.handler = hs.get_handlers().directory_handler self.store = hs.get_datastore() 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")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", clock=MockClock(), db_pool=db_pool, handlers=None, resource_for_federation=Mock(), http_client=None, ) hs.handlers = JustPresenceHandlers(hs) self.store = hs.get_datastore() # Mock the RoomMemberHandler room_member_handler = Mock(spec=[]) hs.handlers.room_member_handler = room_member_handler # Some local users to test with self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test") self.u_clementine = hs.parse_userid("@clementine:test") yield self.store.create_presence(self.u_apple.localpart) yield self.store.set_presence_state( self.u_apple.localpart, {"state": ONLINE, "status_msg": "Online"} ) self.handler = hs.get_handlers().presence_handler self.room_members = [] def get_rooms_for_user(user): if user in self.room_members: return defer.succeed(["a-room"]) else: return defer.succeed([]) room_member_handler.get_rooms_for_user = get_rooms_for_user def get_room_members(room_id): if room_id == "a-room": return defer.succeed(self.room_members) else: return defer.succeed([]) room_member_handler.get_room_members = get_room_members def user_rooms_intersect(userlist): room_member_ids = map(lambda u: u.to_string(), self.room_members) shared = all(map(lambda i: i in room_member_ids, userlist)) return defer.succeed(shared) self.store.user_rooms_intersect = user_rooms_intersect self.mock_start = Mock() self.mock_stop = Mock() self.handler.start_polling_presence = self.mock_start self.handler.stop_polling_presence = self.mock_stop
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) self.store = ProfileStore(hs) self.u_frank = hs.parse_userid("@frank:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) self.store = DirectoryStore(hs) self.room = hs.parse_roomid("!abcde:test") self.alias = hs.parse_roomalias("#my-room:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) self.store = ProfileStore(hs) self.u_frank = hs.parse_userid("@frank:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) self.store = DirectoryStore(hs) self.room = hs.parse_roomid("!abcde:test") self.alias = hs.parse_roomalias("#my-room:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", clock=MockClock(), db_pool=db_pool, ) self.store = PresenceStore(hs) self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) self.store = RegistrationStore(hs) self.user_id = "@my-user:test" self.tokens = ["AbCdEfGhIjKlMnOpQrStUvWxYz", "BcDeFgHiJkLmNoPqRsTuVwXyZa"] self.pwhash = "{xx1}123456789"
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) self.store = RegistrationStore(hs) self.user_id = "@my-user:test" self.tokens = [ "AbCdEfGhIjKlMnOpQrStUvWxYz", "BcDeFgHiJkLmNoPqRsTuVwXyZa" ] self.pwhash = "{xx1}123456789"
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, clock=MockClock(), config=Mock()) self.as_token = "token1" db_pool.runQuery("INSERT INTO application_services(token) VALUES(?)", (self.as_token, )) db_pool.runQuery("INSERT INTO application_services(token) VALUES(?)", ("token2", )) db_pool.runQuery("INSERT INTO application_services(token) VALUES(?)", ("token3", )) # must be done after inserts self.store = ApplicationServiceStore(hs)
def setUp(self): self.mock_federation = Mock(spec=[ "make_query", ]) self.query_handlers = {} def register_query_handler(query_type, handler): 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", ])) self.ratelimiter = hs.get_ratelimiter() self.ratelimiter.send_message.return_value = (True, 0) hs.handlers = ProfileHandlers(hs) self.store = hs.get_datastore() self.frank = hs.parse_userid("@1234ABCD:test") self.bob = hs.parse_userid("@4567:test") self.alice = hs.parse_userid("@alice:remote") yield self.store.create_profile(self.frank.localpart) self.handler = hs.get_handlers().profile_handler # TODO(paul): Icky signal declarings.. booo hs.get_distributor().declare("changed_presencelike_data")
def setUp(self): self.mock_http_client = Mock(spec=[]) self.mock_http_client.put_json = DeferredMockCallable() self.mock_federation_resource = MockHttpResource() db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() self.mock_config = NonCallableMock() self.mock_config.signing_key = [MockKey()] hs = HomeServer( "test", clock=MockClock(), db_pool=db_pool, handlers=None, resource_for_client=Mock(), resource_for_federation=self.mock_federation_resource, http_client=self.mock_http_client, config=self.mock_config, keyring=Mock(), ) hs.handlers = JustPresenceHandlers(hs) self.store = hs.get_datastore() # Some local users to test with self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test") yield self.store.create_presence(self.u_apple.localpart) yield self.store.create_presence(self.u_banana.localpart) # ID of a local user that does not exist self.u_durian = hs.parse_userid("@durian:test") # A remote user self.u_cabbage = hs.parse_userid("@cabbage:elsewhere") self.handler = hs.get_handlers().presence_handler self.mock_start = Mock() self.mock_stop = Mock() self.handler.start_polling_presence = self.mock_start self.handler.stop_polling_presence = self.mock_stop
def setUp(self): self.mock_http_client = Mock(spec=[]) self.mock_http_client.put_json = DeferredMockCallable() self.mock_federation_resource = MockHttpResource() db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() self.mock_config = NonCallableMock() self.mock_config.signing_key = [MockKey()] hs = HomeServer("test", clock=MockClock(), db_pool=db_pool, handlers=None, resource_for_client=Mock(), resource_for_federation=self.mock_federation_resource, http_client=self.mock_http_client, config=self.mock_config, keyring=Mock(), ) hs.handlers = JustPresenceHandlers(hs) self.store = hs.get_datastore() # Some local users to test with self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test") yield self.store.create_presence(self.u_apple.localpart) yield self.store.create_presence(self.u_banana.localpart) # ID of a local user that does not exist self.u_durian = hs.parse_userid("@durian:test") # A remote user self.u_cabbage = hs.parse_userid("@cabbage:elsewhere") self.handler = hs.get_handlers().presence_handler self.mock_start = Mock() self.mock_stop = Mock() self.handler.start_polling_presence = self.mock_start self.handler.stop_polling_presence = self.mock_stop
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) self.store = hs.get_datastore() self.event_factory = hs.get_event_factory() self.u_alice = hs.parse_userid("@alice:test") self.u_bob = hs.parse_userid("@bob:test") self.room1 = hs.parse_roomid("!abc123:test") self.depth = 1
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) # Room events need the full datastore, for persist_event() and # get_room_state() self.store = hs.get_datastore() self.event_factory = hs.get_event_factory(); self.room = hs.parse_roomid("!abcde:test") yield self.store.store_room(self.room.to_string(), room_creator_user_id="@creator:text", is_public=True )
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, clock=MockClock(), config=Mock() ) self.as_token = "token1" db_pool.runQuery( "INSERT INTO application_services(token) VALUES(?)", (self.as_token,) ) db_pool.runQuery( "INSERT INTO application_services(token) VALUES(?)", ("token2",) ) db_pool.runQuery( "INSERT INTO application_services(token) VALUES(?)", ("token3",) ) # must be done after inserts self.store = ApplicationServiceStore(hs)
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) # Room events need the full datastore, for persist_event() and # get_room_state() self.store = hs.get_datastore() self.event_factory = hs.get_event_factory() self.room = hs.parse_roomid("!abcde:test") yield self.store.store_room(self.room.to_string(), room_creator_user_id="@creator:text", is_public=True)
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) # We can't test the RoomMemberStore on its own without the other event # storage logic self.store = hs.get_datastore() self.event_factory = hs.get_event_factory() self.u_alice = hs.parse_userid("@alice:test") self.u_bob = hs.parse_userid("@bob:test") # User elsewhere on another host self.u_charlie = hs.parse_userid("@charlie:elsewhere") self.room = hs.parse_roomid("!abc123:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer("test", db_pool=db_pool, ) # We can't test RoomStore on its own without the DirectoryStore, for # management of the 'room_aliases' table self.store = hs.get_datastore() self.room = hs.parse_roomid("!abcde:test") self.alias = hs.parse_roomalias("#a-room-name:test") self.u_creator = hs.parse_userid("@creator:test") yield self.store.store_room(self.room.to_string(), room_creator_user_id=self.u_creator.to_string(), is_public=True )
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", db_pool=db_pool, ) # We can't test the RoomMemberStore on its own without the other event # storage logic self.store = hs.get_datastore() self.event_factory = hs.get_event_factory() self.u_alice = hs.parse_userid("@alice:test") self.u_bob = hs.parse_userid("@bob:test") # User elsewhere on another host self.u_charlie = hs.parse_userid("@charlie:elsewhere") self.room = hs.parse_roomid("!abc123:test")
def setUp(self): db_pool = SQLiteMemoryDbPool() yield db_pool.prepare() hs = HomeServer( "test", clock=MockClock(), db_pool=db_pool, handlers=None, resource_for_federation=Mock(), http_client=None, ) hs.handlers = JustPresenceHandlers(hs) self.store = hs.get_datastore() # Mock the RoomMemberHandler room_member_handler = Mock(spec=[]) hs.handlers.room_member_handler = room_member_handler # Some local users to test with self.u_apple = hs.parse_userid("@apple:test") self.u_banana = hs.parse_userid("@banana:test") self.u_clementine = hs.parse_userid("@clementine:test") yield self.store.create_presence(self.u_apple.localpart) yield self.store.set_presence_state(self.u_apple.localpart, { "state": ONLINE, "status_msg": "Online" }) self.handler = hs.get_handlers().presence_handler self.room_members = [] def get_rooms_for_user(user): if user in self.room_members: return defer.succeed(["a-room"]) else: return defer.succeed([]) room_member_handler.get_rooms_for_user = get_rooms_for_user def get_room_members(room_id): if room_id == "a-room": return defer.succeed(self.room_members) else: return defer.succeed([]) room_member_handler.get_room_members = get_room_members def user_rooms_intersect(userlist): room_member_ids = map(lambda u: u.to_string(), self.room_members) shared = all(map(lambda i: i in room_member_ids, userlist)) return defer.succeed(shared) self.store.user_rooms_intersect = user_rooms_intersect self.mock_start = Mock() self.mock_stop = Mock() self.handler.start_polling_presence = self.mock_start self.handler.stop_polling_presence = self.mock_stop