How to use the aioxmpp.testutils.run_coroutine function in aioxmpp

To help you get started, we’ve selected a few aioxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horazont / aioxmpp / tests / test_protocol.py View on Github external
def _run_test(self, send, wait_for, actions, stimulus=None,
                  timeout=None, **kwargs):
        return run_coroutine(
            asyncio.gather(
                protocol.send_and_wait_for(
                    self.xmlstream,
                    send,
                    wait_for,
                    timeout=timeout),
                self.xmlstream.run_test(
                    actions,
                    stimulus=stimulus,
                    **kwargs)
            )
        )[0]
github horazont / aioxmpp / tests / vcard / test_service.py View on Github external
new=CoroutineMock()) as mock_send:
            mock_send.side_effect = aioxmpp.XMPPCancelError(
                aioxmpp.ErrorCondition.ITEM_NOT_FOUND
            )
            res = run_coroutine(self.s.get_vcard(TEST_JID1))

        self.assertIsInstance(res, vcard_xso.VCard)
        self.assertEqual(len(res.elements), 0)

        with self.assertRaises(aioxmpp.XMPPCancelError):
            with unittest.mock.patch.object(self.cc, "send",
                                            new=CoroutineMock()) as mock_send:
                mock_send.side_effect = aioxmpp.XMPPCancelError(
                    aioxmpp.ErrorCondition.REMOTE_SERVER_NOT_FOUND
                )
                res = run_coroutine(self.s.get_vcard(TEST_JID1))
github horazont / aioxmpp / tests / muc / test_service.py View on Github external
def test_set_affiliation_rejects_None_mucjid(self):
        with unittest.mock.patch.object(
                self.cc.stream,
                "send",
                new=CoroutineMock()) as send_iq:
            send_iq.return_value = None

            with self.assertRaisesRegex(ValueError,
                                        "mucjid must be bare JID"):
                run_coroutine(self.s.set_affiliation(
                    None,
                    TEST_ENTITY_JID,
                    "outcast",
                    reason="foobar",
                ))

        self.assertFalse(send_iq.mock_calls)
github horazont / aioxmpp / tests / test_callbacks.py View on Github external
def test_connect_and_fire(self):
        coro = CoroutineMock()
        coro.return_value = True

        signal = SyncAdHocSignal()
        signal.connect(coro)

        run_coroutine(signal.fire(1, 2, foo="bar"))

        self.assertSequenceEqual(
            [
                unittest.mock.call(1, 2, foo="bar"),
            ],
            coro.mock_calls
        )
github horazont / aioxmpp / tests / pubsub / test_service.py View on Github external
def test_get_subscription_config(self):
        response = pubsub_xso.Request()
        response.options = unittest.mock.Mock()
        self.cc.send.return_value = response

        result = run_coroutine(self.s.get_subscription_config(
            TEST_TO,
            node="foo",
        ))

        self.assertEqual(
            1,
            len(self.cc.send.mock_calls)
        )

        call, = self.cc.send.mock_calls
        request_iq, = call[1]

        self.assertIsInstance(request_iq, aioxmpp.stanza.IQ)
        self.assertEqual(request_iq.to, TEST_TO)
        self.assertEqual(request_iq.type_, aioxmpp.structs.IQType.GET)
        self.assertIsInstance(request_iq.payload, pubsub_xso.Request)
github horazont / aioxmpp / tests / test_network.py View on Github external
def test_raise_ValueError_if_service_not_supported(self):
        self.base.repeated_query.return_value = [
            MockSRVRecord(0, 1, "xmpp.foo.test.", 5222),
            MockSRVRecord(2, 1, ".", 5222),
        ]

        with self.assertRaisesRegex(
                ValueError,
                r"'xmpp-client' over 'tcp' not supported at b'foo\.test'"):
            run_coroutine(network.lookup_srv(
                b"foo.test",
                "xmpp-client",
            ))
github horazont / aioxmpp / tests / entitycaps / test_service.py View on Github external
fut,
            )

            task = asyncio.async(
                self.c.lookup(base.hash_, base.node)
            )
            run_coroutine(asyncio.sleep(0))

            self.assertFalse(task.done())

            fut.set_exception(ValueError())

            run_coroutine(asyncio.sleep(0))

            with self.assertRaises(KeyError):
                run_coroutine(task)
github jabbercat / jabbercat / tests / test_avatar.py View on Github external
self.ap, "_get_image",
                new=CoroutineMock()
            ))
            _get_image.side_effect = generate_bytes()

            render_avatar_image = stack.enter_context(unittest.mock.patch(
                "jabbercat.avatar.render_avatar_image"
            ))
            render_avatar_image.side_effect = generate_images()

            pic1 = run_coroutine(self.ap.fetch_avatar(
                unittest.mock.sentinel.address1,
            ))
            self.assertIsNotNone(pic1)

            pic2 = run_coroutine(self.ap.fetch_avatar(
                unittest.mock.sentinel.address2,
            ))
            self.assertIsNone(pic2)

        self.assertEqual(
            self.ap.get_avatar(unittest.mock.sentinel.address1),
            unittest.mock.sentinel.image0,
        )

        self.assertEqual(
            self.ap.get_avatar(unittest.mock.sentinel.address2),
            None,
        )

        with self.assertRaises(KeyError):
            self.ap.get_avatar(unittest.mock.sentinel.address)
github horazont / aioxmpp / tests / muc / test_service.py View on Github external
def test_get_room_config_rejects_full_mucjid(self):
        with unittest.mock.patch.object(
                self.cc.stream,
                "send",
                new=CoroutineMock()) as send_iq:
            with self.assertRaisesRegex(ValueError,
                                        "mucjid must be bare JID"):
                run_coroutine(self.s.get_room_config(
                    TEST_MUC_JID.replace(resource="thirdwitch"),
                ))

        self.assertFalse(send_iq.mock_calls)
github jabbercat / jabbercat / tests / test_conversation.py View on Github external
'<div class="payload">'
                '<div class="body"><em>test</em></div>'
                '<div class="flag">'
                '<img title="failed to deliver: '
                'frobnitzed the bar" alt="(error)">'
                '</div>'
                '</div>'
                ''
                ''
                ''
                '<div class="clearfix"></div>'
                ''
                ''
            ),
            run_coroutine(self._obtain_html(), timeout=20),
            ignore_surplus_attr=True,
        )