~ubuntu-branches/ubuntu/precise/telepathy-mission-control-5/precise

« back to all changes in this revision

Viewing changes to tests/twisted/account-requests/cancel.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonny Lamb
  • Date: 2011-01-27 17:54:12 UTC
  • mto: (0.12.1 upstream) (7.1.4 maverick)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110127175412-cijhp5z0763s11cy
Tags: upstream-5.7.2
ImportĀ upstreamĀ versionĀ 5.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Nokia Corporation
 
2
# Copyright (C) 2009 Collabora Ltd.
 
3
#
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation; either
 
7
# version 2.1 of the License, or (at your option) any later version.
 
8
#
 
9
# This library is distributed in the hope that it will be useful, but
 
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
12
# Lesser General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU Lesser General Public
 
15
# License along with this library; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
# 02110-1301 USA
 
18
 
 
19
import dbus
 
20
"""Regression test for the unofficial Account.Interface.Requests API when
 
21
a channel can be created successfully.
 
22
"""
 
23
 
 
24
import dbus
 
25
import dbus.service
 
26
 
 
27
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
 
28
        call_async
 
29
from mctest import exec_test, SimulatedConnection, SimulatedClient, \
 
30
        create_fakecm_account, enable_fakecm_account, SimulatedChannel, \
 
31
        expect_client_setup
 
32
import constants as cs
 
33
 
 
34
def test(q, bus, mc):
 
35
    params = dbus.Dictionary({"account": "someguy@example.com",
 
36
        "password": "secrecy"}, signature='sv')
 
37
    cm_name_ref, account = create_fakecm_account(q, bus, mc, params)
 
38
    conn = enable_fakecm_account(q, bus, mc, account, params)
 
39
 
 
40
    text_fixed_properties = dbus.Dictionary({
 
41
        cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
 
42
        cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
 
43
        }, signature='sv')
 
44
 
 
45
    client = SimulatedClient(q, bus, 'Empathy',
 
46
            observe=[text_fixed_properties], approve=[text_fixed_properties],
 
47
            handle=[text_fixed_properties], bypass_approval=False)
 
48
 
 
49
    # No Approver should be invoked at any point during this test, because the
 
50
    # Channel was Requested
 
51
    def fail_on_approval(e):
 
52
        raise AssertionError('Approver should not be invoked')
 
53
    q.add_dbus_method_impl(fail_on_approval, path=client.object_path,
 
54
            interface=cs.APPROVER, method='AddDispatchOperation')
 
55
 
 
56
    # wait for MC to download the properties
 
57
    expect_client_setup(q, [client])
 
58
 
 
59
    user_action_time = dbus.Int64(1238582606)
 
60
 
 
61
    # chat UI calls ChannelDispatcher.CreateChannel
 
62
    # (or in this case, an equivalent non-standard method on the Account)
 
63
    request = dbus.Dictionary({
 
64
            cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT,
 
65
            cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT,
 
66
            cs.CHANNEL + '.TargetID': 'juliet',
 
67
            }, signature='sv')
 
68
    account_requests = dbus.Interface(account,
 
69
            cs.ACCOUNT_IFACE_NOKIA_REQUESTS)
 
70
    call_async(q, account_requests, 'Create',
 
71
            request, user_action_time, client.bus_name)
 
72
 
 
73
    # chat UI connects to signals and calls ChannelRequest.Proceed() - but not
 
74
    # in this non-standard API, which fires off the request instantly
 
75
    ret, cm_request_call, add_request = q.expect_many(
 
76
            EventPattern('dbus-return', method='Create'),
 
77
            EventPattern('dbus-method-call',
 
78
                interface=cs.CONN_IFACE_REQUESTS, method='CreateChannel',
 
79
                path=conn.object_path, args=[request], handled=False),
 
80
            EventPattern('dbus-method-call', handled=False,
 
81
                interface=cs.CLIENT_IFACE_REQUESTS, method='AddRequest',
 
82
                path=client.object_path),
 
83
            )
 
84
 
 
85
    request_path = ret.value[0]
 
86
 
 
87
    cr = bus.get_object(cs.AM, request_path)
 
88
    request_props = cr.GetAll(cs.CR, dbus_interface=cs.PROPERTIES_IFACE)
 
89
    assert request_props['Account'] == account.object_path
 
90
    assert request_props['Requests'] == [request]
 
91
    assert request_props['UserActionTime'] == user_action_time
 
92
 
 
93
    assert add_request.args[0] == request_path
 
94
    q.dbus_return(add_request.message, signature='')
 
95
 
 
96
    # Actually, never mind.
 
97
    account_requests.Cancel(request_path)
 
98
 
 
99
    # Time passes. A channel is returned.
 
100
 
 
101
    channel_immutable = dbus.Dictionary(request)
 
102
    channel_immutable[cs.CHANNEL + '.InitiatorID'] = conn.self_ident
 
103
    channel_immutable[cs.CHANNEL + '.InitiatorHandle'] = conn.self_handle
 
104
    channel_immutable[cs.CHANNEL + '.Requested'] = True
 
105
    channel_immutable[cs.CHANNEL + '.Interfaces'] = \
 
106
        dbus.Array([], signature='s')
 
107
    channel_immutable[cs.CHANNEL + '.TargetHandle'] = \
 
108
        conn.ensure_handle(cs.HT_CONTACT, 'juliet')
 
109
    channel = SimulatedChannel(conn, channel_immutable)
 
110
 
 
111
    # this order of events is guaranteed by telepathy-spec (since 0.17.14)
 
112
    q.dbus_return(cm_request_call.message,
 
113
            channel.object_path, channel.immutable, signature='oa{sv}')
 
114
    channel.announce()
 
115
 
 
116
    # Channel is unwanted now, MC stabs it in the face
 
117
    accsig, stdsig, _ = q.expect_many(
 
118
            EventPattern('dbus-signal', path=account.object_path,
 
119
                interface=cs.ACCOUNT_IFACE_NOKIA_REQUESTS, signal='Failed'),
 
120
            EventPattern('dbus-signal', path=request_path,
 
121
                interface=cs.CR, signal='Failed'),
 
122
            EventPattern('dbus-method-call', path=channel.object_path,
 
123
                interface=cs.CHANNEL, method='Close', handled=True),
 
124
            )
 
125
 
 
126
if __name__ == '__main__':
 
127
    exec_test(test, {})