def test_on_changed(jid): agent = make_presence_connected_agent() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" agent.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) agent.presence.presenceclient.handle_presence(stanza) contact = agent.presence.get_contact(jid) assert contact["name"] == "My Friend" assert contact["presence"].show == PresenceShow.CHAT stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.AWAY) agent.presence.presenceclient.handle_presence(stanza) contact = agent.presence.get_contact(jid) assert contact["name"] == "My Friend" assert contact["presence"].show == PresenceShow.AWAY
def test_on_changed(jid): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" agent.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) agent.presence.presenceclient.handle_presence(stanza) contact = agent.presence.get_contact(jid) assert contact["name"] == "My Friend" assert contact["presence"].show == PresenceShow.CHAT stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.AWAY) agent.presence.presenceclient.handle_presence(stanza) contact = agent.presence.get_contact(jid) assert contact["name"] == "My Friend" assert contact["presence"].show == PresenceShow.AWAY
def add_fake_contact(self, jid, presence, show=None): jid = JID.fromstr(jid) item = Item(jid=jid) item.approved = True self.presence.roster._update_entry(item) if show: stanza = Presence(from_=jid, type_=presence, show=show) else: stanza = Presence(from_=jid, type_=presence) self.presence.presenceclient.handle_presence(stanza)
def test_on_unsubscribed(jid): agent = make_presence_connected_agent() agent.presence.on_unsubscribed = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBED) agent.presence.roster.handle_unsubscribed(stanza) jid_arg = agent.presence.on_unsubscribed.call_args[0][0] assert jid_arg == str(jid)
def test_ignore_self_presence(): agent = make_presence_connected_agent() jid = agent.jid stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) agent.presence.presenceclient.handle_presence(stanza) with pytest.raises(ContactNotFound): agent.presence.get_contact(jid) assert len(agent.presence.get_contacts()) == 0
def test_get_contacts_with_presence_on_and_off(jid): agent = make_presence_connected_agent() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" agent.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE) agent.presence.presenceclient.handle_presence(stanza) stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) agent.presence.presenceclient.handle_presence(stanza) contacts = agent.presence.get_contacts() assert jid in contacts assert contacts[jid]["name"] == "My Friend" assert contacts[jid]["presence"].type_ == PresenceType.UNAVAILABLE
def test_on_available(jid): agent = make_presence_connected_agent() agent.presence.on_available = Mock() stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE) agent.presence.presenceclient.handle_presence(stanza) jid_arg = agent.presence.on_available.call_args[0][0] stanza_arg = agent.presence.on_available.call_args[0][1] assert jid_arg == str(jid) assert stanza_arg.type_ == PresenceType.AVAILABLE
def test_on_unsubscribe_approve_all(jid): agent = make_presence_connected_agent() agent.presence.approve_all = True agent.aiothread.client.enqueue = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBE) agent.presence.roster.handle_unsubscribe(stanza) assert agent.aiothread.client.enqueue.mock_calls arg = agent.aiothread.client.enqueue.call_args[0][0] assert arg.to == jid.bare() assert arg.type_ == PresenceType.UNSUBSCRIBED
def test_on_unavailable(jid): agent = make_presence_connected_agent() agent.presence.on_unavailable = Mock() agent.presence.presenceclient._presences[jid.bare()] = {"home": None} stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) agent.presence.presenceclient.handle_presence(stanza) jid_arg = agent.presence.on_unavailable.call_args[0][0] stanza_arg = agent.presence.on_unavailable.call_args[0][1] assert jid_arg == str(jid) assert stanza_arg.type_ == PresenceType.UNAVAILABLE
def test_on_unsubscribe(jid): agent = make_presence_connected_agent() future = agent.start(auto_register=False) future.result() agent.presence.on_unsubscribe = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBE) agent.presence.roster.handle_unsubscribe(stanza) jid_arg = agent.presence.on_unsubscribe.call_args[0][0] assert jid_arg == str(jid)
def test_on_unsubscribe(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.on_unsubscribe = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBE) artifact.presence.roster.handle_unsubscribe(stanza) jid_arg = artifact.presence.on_unsubscribe.call_args[0][0] assert jid_arg == str(jid)
def test_on_unsubscribed(jid): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() agent.presence.on_unsubscribed = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBED) agent.presence.roster.handle_unsubscribed(stanza) jid_arg = agent.presence.on_unsubscribed.call_args[0][0] assert jid_arg == str(jid)
def test_get_contacts_with_presence_on_and_off(jid): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" agent.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE) agent.presence.presenceclient.handle_presence(stanza) stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) agent.presence.presenceclient.handle_presence(stanza) contacts = agent.presence.get_contacts() bare_jid = jid.bare() assert bare_jid in contacts assert contacts[bare_jid]["name"] == "My Friend" assert contacts[bare_jid]["presence"].type_ == PresenceType.UNAVAILABLE
def test_ignore_self_presence(): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() jid = agent.jid stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) agent.presence.presenceclient.handle_presence(stanza) with pytest.raises(ContactNotFound): agent.presence.get_contact(jid) assert len(agent.presence.get_contacts()) == 0
def test_on_available(jid): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() agent.presence.on_available = Mock() stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE) agent.presence.presenceclient.handle_presence(stanza) jid_arg = agent.presence.on_available.call_args[0][0] stanza_arg = agent.presence.on_available.call_args[0][1] assert jid_arg == str(jid) assert stanza_arg.type_ == PresenceType.AVAILABLE
def test_on_unavailable(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.on_unavailable = Mock() artifact.presence.presenceclient._presences[jid.bare()] = {"home": None} stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) artifact.presence.presenceclient.handle_presence(stanza) jid_arg = artifact.presence.on_unavailable.call_args[0][0] stanza_arg = artifact.presence.on_unavailable.call_args[0][1] assert jid_arg == str(jid) assert stanza_arg.type_ == PresenceType.UNAVAILABLE
def test_on_unsubscribe_approve_all(jid): agent = MockedPresenceAgentFactory() future = agent.start(auto_register=False) future.result() agent.presence.approve_all = True agent.client.enqueue = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBE) agent.presence.roster.handle_unsubscribe(stanza) assert agent.client.enqueue.mock_calls arg = agent.client.enqueue.call_args[0][0] assert arg.to == jid.bare() assert arg.type_ == PresenceType.UNSUBSCRIBED
def test_get_contacts_with_presence_unavailable(jid): agent = make_presence_connected_agent() item = XSOItem(jid=jid) item.approved = True item.name = "My UnAvailable Friend" agent.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) agent.presence.presenceclient.handle_presence(stanza) contacts = agent.presence.get_contacts() bare_jid = jid.bare() assert bare_jid in contacts assert contacts[bare_jid]["name"] == "My UnAvailable Friend" assert "presence" not in contacts[bare_jid]
def test_get_contacts_with_presence_unavailable(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() item = XSOItem(jid=jid) item.approved = True item.name = "My UnAvailable Friend" artifact.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.UNAVAILABLE) artifact.presence.presenceclient.handle_presence(stanza) contacts = artifact.presence.get_contacts() bare_jid = jid.bare() assert bare_jid in contacts assert contacts[bare_jid]["name"] == "My UnAvailable Friend" assert "presence" not in contacts[bare_jid]