예제 #1
0
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
예제 #2
0
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
예제 #3
0
def test_get_contact(jid):
    agent = make_presence_connected_agent()

    item = XSOItem(jid=jid)
    item.approved = True
    item.name = "My Friend"

    agent.presence.roster._update_entry(item)

    contact = agent.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
예제 #4
0
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()

    assert jid in contacts
    assert contacts[jid]["name"] == "My UnAvailable Friend"

    assert "presence" not in contacts[jid]
예제 #5
0
def test_get_contact(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)

    contact = agent.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
예제 #6
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()

    bare_jid = jid.bare()
    assert bare_jid in contacts
    assert contacts[bare_jid]["name"] == "My Friend"

    assert contacts[bare_jid]["presence"].type_ == PresenceType.UNAVAILABLE
예제 #7
0
def test_get_contacts_with_presence_unavailable(jid):
    agent = MockedPresenceAgentFactory()

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

    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]
예제 #8
0
def test_get_contacts(jid):
    agent = make_presence_connected_agent()

    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)

    contacts = agent.presence.get_contacts()

    bare_jid = jid.bare()
    assert bare_jid in contacts
    assert type(contacts[bare_jid]) == dict
    assert contacts[bare_jid]["approved"]
    assert contacts[bare_jid]["name"] == "My Friend"
    assert contacts[bare_jid]["subscription"] == 'none'
    assert "ask" not in contacts[bare_jid]
    assert "groups" not in contacts[bare_jid]
예제 #9
0
def test_get_contacts_with_presence_on_and_off(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)
    artifact.presence.presenceclient.handle_presence(stanza)
    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 Friend"

    assert contacts[bare_jid]["presence"].type_ == PresenceType.UNAVAILABLE