コード例 #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 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)
コード例 #4
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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)
コード例 #5
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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
コード例 #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()

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

    assert contacts[jid]["presence"].type_ == PresenceType.UNAVAILABLE
コード例 #7
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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
コード例 #8
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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
コード例 #9
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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
コード例 #10
0
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)
コード例 #11
0
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)
コード例 #12
0
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)
コード例 #13
0
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
コード例 #14
0
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
コード例 #15
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
コード例 #16
0
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
コード例 #17
0
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
コード例 #18
0
ファイル: test_presence.py プロジェクト: wxgyy213/spade
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]
コード例 #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]