本文整理汇总了Python中mock.NonCallableMock.membership方法的典型用法代码示例。如果您正苦于以下问题:Python NonCallableMock.membership方法的具体用法?Python NonCallableMock.membership怎么用?Python NonCallableMock.membership使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.NonCallableMock
的用法示例。
在下文中一共展示了NonCallableMock.membership方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: STALE_test_invite_join_public
# 需要导入模块: from mock import NonCallableMock [as 别名]
# 或者: from mock.NonCallableMock import membership [as 别名]
def STALE_test_invite_join_public(self):
room_id = "#foo:blue"
user_id = "@bob:red"
target_user_id = "@bob:red"
content = {"membership": Membership.JOIN}
event = self.hs.get_event_factory().create_event(
etype=RoomMemberEvent.TYPE,
user_id=user_id,
target_user_id=target_user_id,
room_id=room_id,
membership=Membership.JOIN,
content=content,
)
joined = ["red", "blue", "green"]
self.state_handler.handle_new_event.return_value = defer.succeed(True)
self.datastore.get_joined_hosts_for_room.return_value = (
defer.succeed(joined)
)
store_id = "store_id_fooo"
self.datastore.store_room_member.return_value = defer.succeed(store_id)
self.datastore.get_room.return_value = defer.succeed(None)
prev_state = NonCallableMock(name="prev_state")
prev_state.membership = Membership.INVITE
prev_state.sender = "@foo:blue"
self.datastore.get_room_member.return_value = defer.succeed(prev_state)
# Actual invocation
yield self.room_member_handler.change_membership(event)
self.assertTrue(self.federation.handle_new_event.called)
args = self.federation.handle_new_event.call_args[0]
invite_join_event = args[0]
self.assertTrue(InviteJoinEvent.TYPE, invite_join_event.TYPE)
self.assertTrue("blue", invite_join_event.target_host)
self.assertTrue("foo", invite_join_event.room_id)
self.assertTrue(user_id, invite_join_event.user_id)
self.assertFalse(hasattr(invite_join_event, "state_key"))
self.assertEquals(
set(["blue"]),
set(invite_join_event.destinations)
)
self.federation.get_state_for_room.assert_called_once_with(
"blue", "foo"
)
self.assertFalse(self.datastore.store_room_member.called)
self.assertFalse(self.notifier.on_new_room_event.called)
self.assertFalse(self.state_handler.handle_new_event.called)
示例2: test_simple_join
# 需要导入模块: from mock import NonCallableMock [as 别名]
# 或者: from mock.NonCallableMock import membership [as 别名]
def test_simple_join(self):
room_id = "!foo:red"
user_id = "@bob:red"
user = self.hs.parse_userid(user_id)
target_user_id = "@bob:red"
content = {"membership": Membership.JOIN}
event = self.hs.get_event_factory().create_event(
etype=RoomMemberEvent.TYPE,
user_id=user_id,
state_key=target_user_id,
room_id=room_id,
membership=Membership.JOIN,
content=content,
)
joined = ["red", "green"]
self.state_handler.handle_new_event.return_value = defer.succeed(True)
def get_joined(*args):
return defer.succeed(joined)
self.datastore.get_joined_hosts_for_room.side_effect = get_joined
store_id = "store_id_fooo"
self.datastore.persist_event.return_value = defer.succeed(store_id)
self.datastore.get_room.return_value = defer.succeed(1) # Not None.
prev_state = NonCallableMock()
prev_state.membership = Membership.INVITE
prev_state.sender = "@foo:red"
self.datastore.get_room_member.return_value = defer.succeed(prev_state)
join_signal_observer = Mock()
self.distributor.observe("user_joined_room", join_signal_observer)
# Actual invocation
yield self.room_member_handler.change_membership(event)
self.state_handler.handle_new_event.assert_called_once_with(
event, self.snapshot
)
self.federation.handle_new_event.assert_called_once_with(
event, self.snapshot
)
self.assertEquals(
set(["red", "green"]),
set(event.destinations)
)
self.datastore.persist_event.assert_called_once_with(
event
)
self.notifier.on_new_room_event.assert_called_once_with(
event, extra_users=[user])
join_signal_observer.assert_called_with(
user=user, room_id=room_id)