How to use the aioxmpp.stanza.Presence 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_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 / test_stanza.py View on Github external
def test_repr_works_with_incomplete_attributes(self):
        s = stanza.Presence.__new__(stanza.Presence)
        stanza.Presence.from_.mark_incomplete(s)
        stanza.Presence.to.mark_incomplete(s)
        stanza.Presence.id_.mark_incomplete(s)
        stanza.Presence.type_.mark_incomplete(s)
        self.assertEqual(
            repr(s),
            " to= "
            "id= type=>"
github horazont / aioxmpp / tests / presence / test_service.py View on Github external
self.assertIs(
            self.s.get_most_available_stanza(TEST_PEER_JID1),
            st
        )

        staway = stanza.Presence(type_=structs.PresenceType.AVAILABLE,
                                 show=structs.PresenceShow.AWAY,
                                 from_=TEST_PEER_JID1.replace(resource="baz"))
        self.s.handle_presence(staway)

        self.assertIs(
            self.s.get_most_available_stanza(TEST_PEER_JID1),
            st
        )

        stdnd = stanza.Presence(type_=structs.PresenceType.AVAILABLE,
                                show=structs.PresenceShow.DND,
                                from_=TEST_PEER_JID1.replace(resource="bar"))
        self.s.handle_presence(stdnd)

        self.assertEqual(
            len(self.s.get_peer_resources(TEST_PEER_JID1)),
            3
        )

        self.assertIs(
            self.s.get_most_available_stanza(TEST_PEER_JID1),
            stdnd
        )
github horazont / aioxmpp / tests / entitycaps / test_xso.py View on Github external
def test_attr_on_Presence(self):
        self.assertIsInstance(
            stanza.Presence.xep0115_caps,
            xso.Child,
        )
        self.assertSetEqual(
            {
                entitycaps_xso.Caps
            },
            set(stanza.Presence.xep0115_caps._classes)
        )
github horazont / aioxmpp / tests / presence / test_service.py View on Github external
def test_track_available_resources(self):
        st1 = stanza.Presence(type_=structs.PresenceType.AVAILABLE,
                              from_=TEST_PEER_JID1.replace(resource="foo"))
        self.s.handle_presence(st1)

        self.assertDictEqual(
            {
                "foo": st1
            },
            self.s.get_peer_resources(TEST_PEER_JID1)
        )

        st2 = stanza.Presence(type_=structs.PresenceType.AVAILABLE,
                              from_=TEST_PEER_JID1.replace(resource="bar"))
        self.s.handle_presence(st2)

        self.assertDictEqual(
            {
                "foo": st1,
                "bar": st2,
            },
            self.s.get_peer_resources(TEST_PEER_JID1)
        )

        st = stanza.Presence(type_=structs.PresenceType.UNAVAILABLE,
                             from_=TEST_PEER_JID1.replace(resource="foo"))
        self.s.handle_presence(st)

        self.assertDictEqual(
github horazont / aioxmpp / tests / entitycaps / test_service.py View on Github external
def test_handle_outbound_presence_does_not_attach_caps_if_ver_is_None(
            self):
        self.s.ver = None

        presence = stanza.Presence()
        result = self.s.handle_outbound_presence(presence)
        self.assertIs(result, presence)

        self.assertIsNone(presence.xep0115_caps, None)
github horazont / aioxmpp / tests / roster / test_service.py View on Github external
def test_handle_subscribed_emits_event(self):
        st = stanza.Presence(
            type_=structs.PresenceType.SUBSCRIBED,
            from_=TEST_JID
        )

        mock = unittest.mock.Mock()
        self.s.on_subscribed.connect(mock)
        self.s.handle_subscribed(st)
        self.assertSequenceEqual(
            mock.mock_calls,
            [
                unittest.mock.call(st)
            ]
github horazont / aioxmpp / tests / muc / test_xso.py View on Github external
def test_Presence_attr(self):
        self.assertIsInstance(
            stanza.Presence.xep0045_muc_user,
            xso.Child
        )
        self.assertIn(
            muc_xso.UserExt,
            stanza.Presence.xep0045_muc_user._classes
        )
        self.assertFalse(
            stanza.Presence.xep0045_muc_user.required
        )
github horazont / aioxmpp / tests / muc / test_service.py View on Github external
def test__inbound_muc_self_presence_emits_on_nick_changed(self):
        presence = aioxmpp.stanza.Presence(
            type_=aioxmpp.structs.PresenceType.AVAILABLE,
            from_=TEST_MUC_JID.replace(resource="thirdwitch")
        )
        presence.xep0045_muc_user = muc_xso.UserExt(
            items=[
                muc_xso.UserItem(affiliation="member",
                                 role="participant"),
            ],
            status_codes={110},
        )

        original_Occupant = muc_service.Occupant
        with unittest.mock.patch("aioxmpp.muc.service.Occupant") as Occupant:
            first = original_Occupant.from_presence(presence, True)
            Occupant.from_presence.return_value = first
github Terbau / fortnitepy / fortnitepy / xmpp.py View on Github external
async def leave_muc(self) -> None:

        # come back to this. works sometimes? wait for 2 seconds and timeout
        # to manually leave + check if muc messages is sent from correct
        # room (party-id)

        if self.muc_room is not None:
            presence = aioxmpp.stanza.Presence(
                type_=aioxmpp.structs.PresenceType.UNAVAILABLE,
                to=self.muc_room._mucjid
            )
            await self.xmpp_client.send(presence)
            try:
                self.muc_service._muc_exited(self.muc_room)
            except KeyError:
                pass