summaryrefslogtreecommitdiff
path: root/tests/twisted/presence/presence.py
blob: a3c58541a9f93314f89264fd0b03fbacb988c6d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
A simple smoke-test for C.I.SimplePresence

FIXME: test C.I.Presence too
"""

import dbus

from twisted.words.xish import domish, xpath
from twisted.words.protocols.jabber.client import IQ

from hazetest import exec_test

def test(q, bus, conn, stream):
    amy_handle = conn.RequestHandles(1, ['amy@foo.com'])[0]

    # Divergence from Gabble: hazetest responds to all roster gets with an
    # empty roster, so we need to push the roster.
    iq = IQ(stream, 'set')
    query = iq.addElement(('jabber:iq:roster', 'query'))
    item = query.addElement('item')
    item['jid'] = 'amy@foo.com'
    item['subscription'] = 'both'

    stream.send(iq)

    presence = domish.Element((None, 'presence'))
    presence['from'] = 'amy@foo.com'
    show = presence.addElement((None, 'show'))
    show.addContent('away')
    status = presence.addElement((None, 'status'))
    status.addContent('At the pub')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged')
    assert event.args[0] == { amy_handle: (3, 'away', 'At the pub') }

    presence = domish.Element((None, 'presence'))
    presence['from'] = 'amy@foo.com'
    show = presence.addElement((None, 'show'))
    show.addContent('chat')
    status = presence.addElement((None, 'status'))
    status.addContent('I may have been drinking')
    stream.send(presence)

    event = q.expect('dbus-signal', signal='PresencesChanged')
    # FIXME: 'chat' gets lost somewhere between the XMPP stream and what Haze
    # produces.
    assert event.args[0] == { amy_handle: (2, 'available', 'I may have been drinking') }

    conn.Disconnect()
    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])

if __name__ == '__main__':
    exec_test(test)