summaryrefslogtreecommitdiff
path: root/tests/twisted/roster/initial-aliases.py
blob: 0ad823462d9006733e33802c3fd0026209f9f85d (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
"""
Test retrieving the aliases after connection.
"""

from servicetest import (
    assertContains, assertLength
    )
from gabbletest import (
    exec_test, make_result_iq
    )
import ns

def add_contact(iq, jid, alias):
    query = iq.firstChildElement()
    item = query.addElement('item')
    item['jid'] = jid
    item['name'] = alias
    item['subscription'] = 'both'

def test(q, bus, conn, stream):
    """
    Check that when we receive a roster update we emit a single AliasesChanged
    for all the contacts.
    """

    conn.Connect()

    # Gabble asks the server for the initial roster
    event = q.expect('stream-iq', iq_type='get', query_ns=ns.ROSTER)
    result = make_result_iq(stream, event.stanza)

    # We reply with a roster with two contacts
    bob_jid = 'bob.smith@example.com'
    bob_alias = 'Bob Smith'
    add_contact(result, bob_jid, bob_alias)

    alice_jid = 'alice@example.com'
    alice_alias = 'Alice'
    add_contact(result, alice_jid, alice_alias)

    stream.send(result)

    # Check we get a single AliasesChanged for both contacts
    event = q.expect('dbus-signal', signal='AliasesChanged')
    added = event.args[0]

    bob_handle, alice_handle = conn.get_contact_handles_sync(
            [bob_jid, alice_jid])

    assertLength(2, added)
    assertContains((bob_handle, bob_alias), added)
    assertContains((alice_handle, alice_alias), added)

if __name__ == '__main__':
    exec_test(test, do_connect=False)