示例#1
0
def test_get_contacts_empty():
    artifact = MockedConnectedArtifactFactory()

    future = artifact.start(auto_register=False)
    future.result()

    assert artifact.presence.get_contacts() == {}
示例#2
0
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
示例#3
0
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")
示例#4
0
def test_get_priority():
    artifact = MockedConnectedArtifactFactory(priority=10)

    future = artifact.start(auto_register=False)
    future.result()
    artifact.mock_presence()

    assert artifact.presence.priority == 10
示例#5
0
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"))
示例#6
0
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"}
示例#7
0
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"}
示例#8
0
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()
示例#9
0
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
示例#10
0
def test_set_unavailable():
    artifact = MockedConnectedArtifactFactory()

    future = artifact.start(auto_register=False)
    future.result()

    artifact.presence.set_unavailable()

    assert not artifact.presence.is_available()
示例#11
0
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
示例#12
0
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)
示例#13
0
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
示例#14
0
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
示例#15
0
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
示例#16
0
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
示例#17
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
示例#18
0
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
示例#19
0
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]
示例#20
0
def test_is_alive():
    artifact = MockedConnectedArtifactFactory()
    assert artifact.is_alive() is False
    future = artifact.start()
    future.result()
    assert artifact.is_alive()
示例#21
0
def test_run():
    artifact = MockedConnectedArtifactFactory()
    future = artifact.start()
    future.result()
    artifact.join()
    assert artifact.get("test_passed")