mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-07 08:42:01 +00:00
Fix room handler test
This commit is contained in:
parent
5d439b127b
commit
b01159f234
@ -58,9 +58,8 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
"profile_handler",
|
"profile_handler",
|
||||||
"federation_handler",
|
"federation_handler",
|
||||||
]),
|
]),
|
||||||
auth=NonCallableMock(spec_set=["check"]),
|
auth=NonCallableMock(spec_set=["check", "add_auth_events"]),
|
||||||
state_handler=NonCallableMock(spec_set=[
|
state_handler=NonCallableMock(spec_set=[
|
||||||
"handle_new_event",
|
|
||||||
"annotate_state_groups",
|
"annotate_state_groups",
|
||||||
]),
|
]),
|
||||||
config=self.mock_config,
|
config=self.mock_config,
|
||||||
@ -68,6 +67,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.federation = NonCallableMock(spec_set=[
|
self.federation = NonCallableMock(spec_set=[
|
||||||
"handle_new_event",
|
"handle_new_event",
|
||||||
|
"send_invite",
|
||||||
"get_state_for_room",
|
"get_state_for_room",
|
||||||
])
|
])
|
||||||
|
|
||||||
@ -110,7 +110,6 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
joined = ["red", "green"]
|
joined = ["red", "green"]
|
||||||
|
|
||||||
self.state_handler.handle_new_event.return_value = defer.succeed(True)
|
|
||||||
self.datastore.get_joined_hosts_for_room.return_value = (
|
self.datastore.get_joined_hosts_for_room.return_value = (
|
||||||
defer.succeed(joined)
|
defer.succeed(joined)
|
||||||
)
|
)
|
||||||
@ -120,6 +119,18 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
self.datastore.get_room_member.return_value = defer.succeed(None)
|
self.datastore.get_room_member.return_value = defer.succeed(None)
|
||||||
|
|
||||||
|
event.state_events = {
|
||||||
|
(RoomMemberEvent.TYPE, "@alice:green"): self._create_member(
|
||||||
|
user_id="@alice:green",
|
||||||
|
room_id=room_id,
|
||||||
|
),
|
||||||
|
(RoomMemberEvent.TYPE, "@bob:red"): self._create_member(
|
||||||
|
user_id="@bob:red",
|
||||||
|
room_id=room_id,
|
||||||
|
),
|
||||||
|
(RoomMemberEvent.TYPE, target_user_id): event,
|
||||||
|
}
|
||||||
|
|
||||||
# Actual invocation
|
# Actual invocation
|
||||||
yield self.room_member_handler.change_membership(event)
|
yield self.room_member_handler.change_membership(event)
|
||||||
|
|
||||||
@ -128,7 +139,7 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
set(["blue", "red", "green"]),
|
set(["red", "green"]),
|
||||||
set(event.destinations)
|
set(event.destinations)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -147,22 +158,14 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
room_id = "!foo:red"
|
room_id = "!foo:red"
|
||||||
user_id = "@bob:red"
|
user_id = "@bob:red"
|
||||||
user = self.hs.parse_userid(user_id)
|
user = self.hs.parse_userid(user_id)
|
||||||
target_user_id = "@bob:red"
|
|
||||||
content = {"membership": Membership.JOIN}
|
|
||||||
|
|
||||||
event = self.hs.get_event_factory().create_event(
|
event = self._create_member(
|
||||||
etype=RoomMemberEvent.TYPE,
|
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
state_key=target_user_id,
|
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
membership=Membership.JOIN,
|
|
||||||
content=content,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
joined = ["red", "green"]
|
joined = ["red", "green"]
|
||||||
|
|
||||||
self.state_handler.handle_new_event.return_value = defer.succeed(True)
|
|
||||||
|
|
||||||
def get_joined(*args):
|
def get_joined(*args):
|
||||||
return defer.succeed(joined)
|
return defer.succeed(joined)
|
||||||
|
|
||||||
@ -180,6 +183,14 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
join_signal_observer = Mock()
|
join_signal_observer = Mock()
|
||||||
self.distributor.observe("user_joined_room", join_signal_observer)
|
self.distributor.observe("user_joined_room", join_signal_observer)
|
||||||
|
|
||||||
|
event.state_events = {
|
||||||
|
(RoomMemberEvent.TYPE, "@alice:green"): self._create_member(
|
||||||
|
user_id="@alice:green",
|
||||||
|
room_id=room_id,
|
||||||
|
),
|
||||||
|
(RoomMemberEvent.TYPE, user_id): event,
|
||||||
|
}
|
||||||
|
|
||||||
# Actual invocation
|
# Actual invocation
|
||||||
yield self.room_member_handler.change_membership(event)
|
yield self.room_member_handler.change_membership(event)
|
||||||
|
|
||||||
@ -203,6 +214,16 @@ class RoomMemberHandlerTestCase(unittest.TestCase):
|
|||||||
user=user, room_id=room_id
|
user=user, room_id=room_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _create_member(self, user_id, room_id):
|
||||||
|
return self.hs.get_event_factory().create_event(
|
||||||
|
etype=RoomMemberEvent.TYPE,
|
||||||
|
user_id=user_id,
|
||||||
|
state_key=user_id,
|
||||||
|
room_id=room_id,
|
||||||
|
membership=Membership.JOIN,
|
||||||
|
content={"membership": Membership.JOIN},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class RoomCreationTest(unittest.TestCase):
|
class RoomCreationTest(unittest.TestCase):
|
||||||
|
|
||||||
@ -228,9 +249,8 @@ class RoomCreationTest(unittest.TestCase):
|
|||||||
"room_member_handler",
|
"room_member_handler",
|
||||||
"federation_handler",
|
"federation_handler",
|
||||||
]),
|
]),
|
||||||
auth=NonCallableMock(spec_set=["check"]),
|
auth=NonCallableMock(spec_set=["check", "add_auth_events"]),
|
||||||
state_handler=NonCallableMock(spec_set=[
|
state_handler=NonCallableMock(spec_set=[
|
||||||
"handle_new_event",
|
|
||||||
"annotate_state_groups",
|
"annotate_state_groups",
|
||||||
]),
|
]),
|
||||||
ratelimiter=NonCallableMock(spec_set=[
|
ratelimiter=NonCallableMock(spec_set=[
|
||||||
@ -259,6 +279,11 @@ class RoomCreationTest(unittest.TestCase):
|
|||||||
])
|
])
|
||||||
self.room_member_handler = self.handlers.room_member_handler
|
self.room_member_handler = self.handlers.room_member_handler
|
||||||
|
|
||||||
|
def annotate(event):
|
||||||
|
event.state_events = {}
|
||||||
|
return defer.succeed(None)
|
||||||
|
self.state_handler.annotate_state_groups.side_effect = annotate
|
||||||
|
|
||||||
def hosts(room):
|
def hosts(room):
|
||||||
return defer.succeed([])
|
return defer.succeed([])
|
||||||
self.datastore.get_joined_hosts_for_room.side_effect = hosts
|
self.datastore.get_joined_hosts_for_room.side_effect = hosts
|
||||||
|
Loading…
Reference in New Issue
Block a user