How to use aioxmpp - 10 common examples

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 / xso / test_model.py View on Github external
def test_unparse_to_node_handle_child(self):
        class ClsLeaf(xso.XSO):
            TAG = "baz"
            text = xso.Text()

        class Cls(xso.XSO):
            TAG = "bar"
            child = xso.Child([ClsLeaf])

        obj = Cls()
        obj.child = ClsLeaf()
        obj.child.text = "fnord"

        self._unparse_test(
            obj,
            etree.fromstring("fnord")
        )
github jabbercat / jabbercat / tests / test_conversation.py View on Github external
def setUp(self):
        self.logger = unittest.mock.Mock(spec=logging.Logger)
        self.profile = Qt.QWebEngineProfile()
        self.account_jid = aioxmpp.JID.fromstr("juliet@capulet.lit")
        self.conversation_jid = aioxmpp.JID.fromstr("romeo@montague.lit")
        self.page = conversation.MessageViewPage(
            self.profile,
            logging.getLogger(
                ".".join([__name__, type(self).__qualname__])
            ),
            self.account_jid,
            self.conversation_jid,
        )
        run_coroutine(self.page.ready_event.wait())
github horazont / aioxmpp / tests / test_node.py View on Github external
def test_change_presence_to_available(self):
        self.client.presence = structs.PresenceState(
            available=True,
            show="chat")

        run_coroutine(self.xmlstream.run_test([
        ]+self.resource_binding+[
            XMLStreamMock.Send(
                stanza.Presence(type_=None,
                                show="chat",
                                id_="autoset"),
                response=XMLStreamMock.Receive(
                    stanza.Presence(type_=None,
                                    show="chat",
                                    id_="autoset")
                )
            )
        ]))

        self.presence_sent_rec.assert_called_once_with()
github horazont / aioxmpp / tests / disco / test_service.py View on Github external
import aioxmpp.disco.service as disco_service
import aioxmpp.disco.xso as disco_xso
import aioxmpp.stanza as stanza
import aioxmpp.structs as structs
import aioxmpp.errors as errors

from aioxmpp.utils import namespaces

from aioxmpp.testutils import (
    make_connected_client,
    run_coroutine,
    CoroutineMock,
)


TEST_JID = structs.JID.fromstr("foo@bar.example")


class TestNode(unittest.TestCase):
    def test_init(self):
        n = disco_service.Node()
        self.assertSequenceEqual(
            [],
            list(n.iter_identities(unittest.mock.sentinel.stanza))
        )
        self.assertSetEqual(
            {namespaces.xep0030_info},
            set(n.iter_features(unittest.mock.sentinel.stanza))
        )
        self.assertSequenceEqual(
            [],
            list(n.iter_items(unittest.mock.sentinel.stanza))
github horazont / aioxmpp / tests / test_protocol.py View on Github external
exc = ValueError()
        t, p = self._make_stream(to=TEST_PEER)
        run_coroutine(
            t.run_test(
                [
                    TransportMock.Write(
                        STREAM_HEADER,
                        response=[
                            TransportMock.LoseConnection(exc=exc)
                        ]),
                ],
                partial=True
            )
        )
        with self.assertRaises(ValueError) as ctx:
            p.send_xso(stanza.IQ(structs.IQType.GET))
        self.assertIs(exc, ctx.exception)
github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test_unparse_to_node_handle_text(self):
        class Cls(xso.XSO):
            TAG = "bar"
            text = xso.Text()

        obj = Cls()
        obj.text = "foobar"

        self._unparse_test(
            obj,
            etree.fromstring("foobar")
        )
github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test_unparse_to_node_handle_child(self):
        class ClsLeaf(xso.XSO):
            TAG = "baz"
            text = xso.Text()

        class Cls(xso.XSO):
            TAG = "bar"
            child = xso.Child([ClsLeaf])

        obj = Cls()
        obj.child = ClsLeaf()
        obj.child.text = "fnord"

        self._unparse_test(
            obj,
            etree.fromstring("fnord")
        )
github horazont / aioxmpp / tests / xso / test_model.py View on Github external
def test_unparse_to_node_create_node(self):
        self._unparse_test(
            self.obj,
            etree.fromstring("")
        )
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))