예제 #1
0
    def setUp(self):
        self.cc = make_connected_client()
        self.cc.stream.send = CoroutineMock()
        self.cc.stream.send.side_effect = AssertionError("not configured")
        self.cc.local_jid = LOCAL_JID
        deps = {
            im_service.ConversationService: im_service.ConversationService(
                self.cc
            ),
            im_dispatcher.IMDispatcher: im_dispatcher.IMDispatcher(
                self.cc
            )
        }
        self.svc = unittest.mock.Mock(["client", "_conversation_left"])
        self.svc.client = self.cc
        self.s = p2p.Service(self.cc, dependencies=deps)

        self.listener = unittest.mock.Mock()

        for ev in ["on_conversation_new", "on_conversation_left"]:
            listener = getattr(self.listener, ev)
            signal = getattr(self.s, ev)
            listener.return_value = None
            signal.connect(listener)

        for ev in ["on_conversation_added"]:
            listener = getattr(self.listener, ev)
            signal = getattr(deps[im_service.ConversationService], ev)
            listener.return_value = None
            signal.connect(listener)
예제 #2
0
    def setUp(self):
        self.cc = make_connected_client()
        self.cc.local_jid = TEST_LOCAL.replace(resource="we")
        self.disco_client = aioxmpp.DiscoClient(self.cc)
        self.carbons = aioxmpp.CarbonsClient(self.cc, dependencies={
            aioxmpp.DiscoClient: self.disco_client,
        })
        self.s = dispatcher.IMDispatcher(self.cc, dependencies={
            aioxmpp.CarbonsClient: self.carbons,
        })
        self.listener = unittest.mock.Mock()

        for filter_ in ["message_filter", "presence_filter"]:
            cb = getattr(self.listener, filter_)
            cb.side_effect = lambda x, *args, **kwargs: x
            filter_chain = getattr(self.s, filter_)
            filter_chain.register(cb, 0)