def test_get_contacts_empty(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() assert artifact.presence.get_contacts() == {}
def test_on_changed(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" artifact.presence.roster._update_entry(item) stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) artifact.presence.presenceclient.handle_presence(stanza) contact = artifact.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) artifact.presence.presenceclient.handle_presence(stanza) contact = artifact.presence.get_contact(jid) assert contact["name"] == "My Friend" assert contact["presence"].show == PresenceShow.AWAY
def test_get_invalid_jid_contact(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() with pytest.raises(ContactNotFound): artifact.presence.get_contact(JID.fromstr("invalid@contact"))
def test_get_priority(): artifact = MockedConnectedArtifactFactory(priority=10) future = artifact.start(auto_register=False) future.result() artifact.mock_presence() assert artifact.presence.priority == 10
def test_get_status_dict(): artifact = MockedConnectedArtifactFactory(status={"en": "Working"}) future = artifact.start(auto_register=False) future.result() artifact.mock_presence() assert artifact.presence.status == {"en": "Working"}
def test_get_invalid_str_contact(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() with pytest.raises(AttributeError): artifact.presence.get_contact("invalid@contact")
def test_set_unavailable(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.set_unavailable() assert not artifact.presence.is_available()
def test_get_state_show(): artifact = MockedConnectedArtifactFactory(available=True, show=PresenceShow.AWAY) future = artifact.start(auto_register=False) future.result() artifact.mock_presence() assert artifact.presence.state.show == PresenceShow.AWAY
def test_set_presence_status_dict(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.set_presence(status={"en": "Lunch"}) assert artifact.presence.status == {"en": "Lunch"}
def test_set_presence_available(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.set_presence(state=PresenceState(available=True)) assert artifact.presence.is_available()
def test_set_available_with_show(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.mock_presence() artifact.presence.set_available(show=PresenceShow.CHAT) assert artifact.presence.is_available() assert artifact.presence.state.show == PresenceShow.CHAT
def test_on_unsubscribed(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.on_unsubscribed = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBED) artifact.presence.roster.handle_unsubscribed(stanza) jid_arg = artifact.presence.on_unsubscribed.call_args[0][0] assert jid_arg == str(jid)
def test_set_presence(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.set_presence(state=PresenceState(True, PresenceShow.PLAIN), status="Lunch", priority=2) assert artifact.presence.is_available() assert artifact.presence.state.show == PresenceShow.PLAIN assert artifact.presence.status == {None: "Lunch"} assert artifact.presence.priority == 2
def test_approve(jid): peer_jid = str(jid) artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.client.enqueue = Mock() artifact.presence.approve(peer_jid) assert artifact.client.enqueue.mock_calls arg = artifact.client.enqueue.call_args[0][0] assert arg.to == jid.bare() assert arg.type_ == PresenceType.SUBSCRIBED
def test_set_get(): artifact = MockedConnectedArtifactFactory() assert artifact.get("A_KEY") is None artifact.set("A_KEY", True) assert artifact.get("A_KEY") artifact.set("A_KEY", 1234) assert artifact.get("A_KEY") == 1234
def test_on_available(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.on_available = Mock() stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE) artifact.presence.presenceclient.handle_presence(stanza) jid_arg = artifact.presence.on_available.call_args[0][0] stanza_arg = artifact.presence.on_available.call_args[0][1] assert jid_arg == str(jid) assert stanza_arg.type_ == PresenceType.AVAILABLE
def test_ignore_self_presence(): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() jid = artifact.jid stanza = Presence(from_=jid, type_=PresenceType.AVAILABLE, show=PresenceShow.CHAT) artifact.presence.presenceclient.handle_presence(stanza) with pytest.raises(ContactNotFound): artifact.presence.get_contact(jid) assert len(artifact.presence.get_contacts()) == 0
def test_on_unsubscribe_approve_all(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() artifact.presence.approve_all = True artifact.client.enqueue = Mock() stanza = Presence(from_=jid, type_=PresenceType.UNSUBSCRIBE) artifact.presence.roster.handle_unsubscribe(stanza) assert artifact.client.enqueue.mock_calls arg = artifact.client.enqueue.call_args[0][0] assert arg.to == jid.bare() assert arg.type_ == PresenceType.UNSUBSCRIBED
def test_get_contact(jid): artifact = MockedConnectedArtifactFactory() future = artifact.start(auto_register=False) future.result() item = XSOItem(jid=jid) item.approved = True item.name = "My Friend" artifact.presence.roster._update_entry(item) contact = artifact.presence.get_contact(jid) assert type(contact) == dict assert contact["approved"] assert contact["name"] == "My Friend" assert contact["subscription"] == "none" assert "ask" not in contact assert "groups" not in contact
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]
def test_name(): artifact = MockedConnectedArtifactFactory() assert artifact.name == "fake"
def test_run(): artifact = MockedConnectedArtifactFactory() future = artifact.start() future.result() artifact.join() assert artifact.get("test_passed")
def test_is_alive(): artifact = MockedConnectedArtifactFactory() assert artifact.is_alive() is False future = artifact.start() future.result() assert artifact.is_alive()