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

« back to all changes in this revision

Viewing changes to test/twisted/account-manager/service.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) 2010 Nokia Corporation
2
 
# Copyright (C) 2010 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
 
import dbus
21
 
import dbus.service
22
 
 
23
 
from servicetest import EventPattern, tp_name_prefix, call_async, assertEquals
24
 
from mctest import exec_test, create_fakecm_account
25
 
import constants as cs
26
 
 
27
 
def test(q, bus, mc):
28
 
    params = dbus.Dictionary({"account": "wjt@example.com",
29
 
        "password": "secrecy"}, signature='sv')
30
 
    (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
31
 
 
32
 
    srv_name = 'fu-bar-42'
33
 
    account_iface = dbus.Interface(account, cs.ACCOUNT)
34
 
    account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
35
 
 
36
 
    # defaults to the empty string
37
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), '');
38
 
    
39
 
    # set to a new value after creation
40
 
    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Service', srv_name);
41
 
    q.expect_many(
42
 
        EventPattern('dbus-signal',
43
 
            path=account.object_path,
44
 
            signal='AccountPropertyChanged',
45
 
            interface=cs.ACCOUNT,
46
 
            args=[{'Service': srv_name}]),
47
 
        EventPattern('dbus-return', method='Set'),
48
 
        )
49
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), srv_name)
50
 
 
51
 
    # set to an invalid value (no actual change should occur)
52
 
 
53
 
    # leading non-alphabetic (make sure _ isn't considered alphabetic)
54
 
    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Service', '_fu-bar');
55
 
    q.expect_many(EventPattern('dbus-error', method='Set'))
56
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), srv_name)
57
 
 
58
 
    # leading non-alphabetic
59
 
    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Service', '.moose');
60
 
    q.expect_many(EventPattern('dbus-error', method='Set'))
61
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), srv_name)
62
 
 
63
 
    # gregexes have an option to be lenient about trailing newlines:
64
 
    # this makes sure we haven't made that mistake
65
 
    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Service', srv_name + '\n');
66
 
    q.expect_many(EventPattern('dbus-error', method='Set'))
67
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), srv_name)
68
 
 
69
 
    # set to an empty string
70
 
    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Service', '');
71
 
    q.expect_many(EventPattern('dbus-return', method='Set'))
72
 
    assertEquals(account_props.Get(cs.ACCOUNT, 'Service'), '')
73
 
 
74
 
    # test creation with a service
75
 
    account_manager = bus.get_object(cs.AM, cs.AM_PATH)
76
 
    am_iface = dbus.Interface(account_manager, cs.AM)
77
 
 
78
 
    service_prop = dbus.Dictionary({
79
 
        cs.ACCOUNT + '.Service': "moomin-troll",
80
 
        }, signature='sv')
81
 
 
82
 
    call_async(q, am_iface, 'CreateAccount',
83
 
            'fakecm',       # Connection_Manager
84
 
            'fakeprotocol', # Protocol
85
 
            'fakeaccount',  # Display_Name
86
 
            params,         # Parameters
87
 
            service_prop,   # Properties
88
 
            )
89
 
 
90
 
    ret = q.expect('dbus-return', method='CreateAccount')
91
 
    path = ret.value[0]
92
 
    account = bus.get_object(cs.tp_name_prefix + '.AccountManager', path)
93
 
    if_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
94
 
    props = if_props.GetAll(cs.ACCOUNT)
95
 
    assertEquals(props.get('Service'), 'moomin-troll')
96
 
 
97
 
    # attempt creation with a bogus service
98
 
    service_prop = dbus.Dictionary({cs.ACCOUNT + '.Service': "1337"},
99
 
                                   signature='sv')
100
 
 
101
 
    call_async(q, am_iface, 'CreateAccount',
102
 
            'fakecm',       # Connection_Manager
103
 
            'fakeprotocol', # Protocol
104
 
            'fakeaccount',  # Display_Name
105
 
            params,         # Parameters
106
 
            service_prop,   # Properties
107
 
            )
108
 
 
109
 
    ret = q.expect('dbus-error', method='CreateAccount')
110
 
 
111
 
if __name__ == '__main__':
112
 
    exec_test(test, {})