本文整理匯總了Python中mock.NonCallableMock.sender方法的典型用法代碼示例。如果您正苦於以下問題:Python NonCallableMock.sender方法的具體用法?Python NonCallableMock.sender怎麽用?Python NonCallableMock.sender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mock.NonCallableMock
的用法示例。
在下文中一共展示了NonCallableMock.sender方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: STALE_test_invite_join_public
# 需要導入模塊: from mock import NonCallableMock [as 別名]
# 或者: from mock.NonCallableMock import sender [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 sender [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)