# Create an object that will proxy for a particular remote object. manager = bus.get_object(cs.MC, YTST_ACCOUNT_MANAGER_PATH) manager_ytst = dbus.Interface(manager, YTST_ACCOUNT_MANAGER_IFACE) manager_ytst.Hold() q.expect('dbus-signal', signal='AccountPropertyChanged', path=YTST_ACCOUNT_PATH, predicate=is_account_going_online) # This second hold should cancel the release manager_ytst.Release() manager_ytst.Hold() try: q.expect('dbus-signal', signal='AccountPropertyChanged', path=YTST_ACCOUNT_PATH, predicate=is_account_going_offline) except TimeoutError: pass else: assert False if __name__ == '__main__': exec_test(test_account_exists, {}) exec_test(test_hold_and_release, {}) exec_test(test_hold_and_no_release, {})
assert channels[0][0] == channel.object_path, channels assert channels[0][1] == channel_immutable, channels # Observer says "OK, go" q.dbus_return(a.message, signature='') q.dbus_return(e.message, signature='') # Empathy is asked to handle the channel e = q.expect('dbus-method-call', path=client.object_path, interface=cs.HANDLER, method='HandleChannels', handled=False) assert e.args[0] == account.object_path, e.args assert e.args[1] == conn.object_path, e.args channels = e.args[2] assert len(channels) == 1, channels assert channels[0][0] == channel.object_path, channels assert channels[0][1] == channel_immutable, channels assert e.args[3] == [request_path], e.args assert e.args[4] == user_action_time assert isinstance(e.args[5], dict) assert len(e.args) == 6 if __name__ == '__main__': exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, pass_kwargs=True)
empathy.release_name() e = q.expect('dbus-signal', signal='NameOwnerChanged', predicate=(lambda e: e.args[0] == empathy.bus_name and e.args[2] == ''), ) empathy_unique_name = e.args[1] empathy_bus.flush() empathy_bus.close() # In response, the channels that were being handled by Empathy are closed. # Kopete's channel is *not* closed. q.expect_many( EventPattern('dbus-signal', signal='NameOwnerChanged', predicate=(lambda e: e.args[0] == empathy_unique_name and e.args[2] == '')), EventPattern('dbus-method-call', path=chan.object_path, method='Close'), EventPattern('dbus-method-call', path=claimed_chan.object_path, method='Close'), ) sync_dbus(bus, q, mc) q.unforbid_events(forbidden) if __name__ == '__main__': exec_test(test, {})
for server_delays in (True, False): if have_remote_avatar: # the avatars have to be unique, otherwise the # avatar cache will break our RequestAvatars expectation remote_avatar = 'remote%d' % i i += 1 else: remote_avatar = '' accounts.append(Account(fake_accounts_service, accounts_dir, avatars_persist=True, server_delays=server_delays, local_avatar=local_avatar, remote_avatar=remote_avatar)) return accounts def test(q, bus, unused, **kwargs): simulated_cm = SimulatedConnectionManager(q, bus) fake_accounts_service = kwargs['fake_accounts_service'] accounts = preseed(q, bus, fake_accounts_service) mc = MC(q, bus) for account in accounts: account.test(q, bus, mc) if __name__ == '__main__': exec_test(test, {}, preload_mc=False, use_fake_accounts_service=True, pass_kwargs=True)
# ~/.mission-control/accounts.cfg, as used in MC 5.0 to 5.13.1 # # Copyright (C) 2009-2010 Nokia Corporation # Copyright (C) 2009-2014 Collabora Ltd. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA from storage_helper import test_keyfile from mctest import exec_test def test_5_12(q, bus, mc): test_keyfile(q, bus, mc, '5.12') if __name__ == '__main__': exec_test(test_5_12, {}, preload_mc=False, use_fake_accounts_service=False)
events = q.expect_many(*try_to_connect) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', account_tail.replace('/', '_'), 'ezio', has_presence=True) q.dbus_return(events[-1].message, conn.bus_name, conn.object_path, signature='so') # we are connected: deleting the account should # disconnect us fake_accounts_service.delete_account(account_tail) q.expect_many( EventPattern('dbus-signal', signal='AccountRemoved', args=[account_path]), EventPattern('dbus-signal', signal='Removed', path=account_path), EventPattern('dbus-method-call', method='Disconnect'), ) if __name__ == '__main__': exec_test(test, {}, pass_kwargs=True)
# Set online presence presence = dbus.Struct( (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', presence) e = q.expect('dbus-method-call', method='RequestConnection', args=['fakeprotocol', params], destination=tp_name_prefix + '.ConnectionManager.fakecm', path=tp_path_prefix + '/ConnectionManager/fakecm', interface=tp_name_prefix + '.ConnectionManager', handled=False) q.dbus_raise(e.message, cs.NOT_IMPLEMENTED, "CM is broken") # MC should report the connection dying. e = q.expect('dbus-signal', signal='AccountPropertyChanged', predicate=lambda e: 'ConnectionError' in e.args[0]) changed, = e.args assertEquals('/', changed['Connection']) assertEquals(cs.CONN_STATUS_DISCONNECTED, changed['ConnectionStatus']) assertEquals(cs.CSR_NONE_SPECIFIED, changed['ConnectionStatusReason']) assertEquals(cs.NOT_IMPLEMENTED, changed['ConnectionError']) if __name__ == '__main__': exec_test(test)
assert kf[group]['Nickname'] == 'Joe Bloggs', kf # Reactivate MC account_manager, properties, interfaces = resuscitate_mc(q, bus, mc) account = get_fakecm_account(bus, mc, account_path) account_iface = dbus.Interface(account, cs.ACCOUNT) # Delete the account assert account_iface.Remove() is None account_event, account_manager_event = q.expect_many( EventPattern('dbus-signal', path=account_path, signal='Removed', interface=cs.ACCOUNT, args=[] ), EventPattern('dbus-signal', path=cs.AM_PATH, signal='AccountRemoved', interface=cs.AM, args=[account_path] ), ) # Check the account is correctly deleted kf = read_account_keyfile() assert group not in kf, kf if __name__ == '__main__': exec_test(test, {}, timeout=10, use_fake_accounts_service=False)
account.Properties.Get(cs.ACCOUNT, 'RequestedPresence')) # But if we get disconnected before RequestConnection returns, MC should # clean up the new connection when it does, rather than trying to sign it # in. connect_event = [ EventPattern('dbus-method-call', method='Connect'), ] q.forbid_events(connect_event) mc.connectivity.go_offline() # Make sure that MC has noticed that the network connection has gone away. sync_connectivity_state(mc) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', account.object_path.split('/')[-1], 'myself') q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so') q.expect('dbus-method-call', method='Disconnect') # So now the user gives up and sets their RequestedPresence to offline. # Because this account does not ConnectAutomatically, if the network # connection comes back up the account should not be brought back online. q.forbid_events(request_connection_event) account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) mc.connectivity.go_online() # Make sure MC has noticed that the network connection has come back. sync_connectivity_state(mc) if __name__ == '__main__': exec_test(test, initially_online=False)
q.expect('dbus-method-call', method='Disconnect') q.unforbid_events(try_to_connect) else: q.unforbid_events(try_to_connect) fake_accounts_service.update_attributes(account_tail, { 'Enabled': True, 'ConnectAutomatically': True, }) events = q.expect_many(*try_to_connect) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', account_tail.replace('/', '_'), 'ezio', has_presence=True) q.dbus_return(events[-1].message, conn.bus_name, conn.object_path, signature='so') # we are connected: deleting the account should # disconnect us fake_accounts_service.delete_account(account_tail) q.expect_many( EventPattern('dbus-signal', signal='AccountRemoved', args=[account_path]), EventPattern('dbus-signal', signal='Removed', path=account_path), EventPattern('dbus-method-call', method='Disconnect'), ) if __name__ == '__main__': exec_test(test, {}, pass_kwargs=True)
conn = SimulatedConnection(q, cm_bus, 'fakecm', 'fakeprotocol', '_', 'myself', has_presence=True) q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so') q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) # Connect succeeds conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # CM crashes conn.release_name() simulated_cm.release_name() cm_bus.flush() cm_bus.close() # MC should report the connection dying. e = q.expect('dbus-signal', signal='AccountPropertyChanged', predicate=lambda e: 'ConnectionError' in e.args[0]) changed, = e.args assertEquals('/', changed['Connection']) assertEquals(cs.CONN_STATUS_DISCONNECTED, changed['ConnectionStatus']) # In the absence of a better code, None will have to do. assertEquals(cs.CSR_NONE_SPECIFIED, changed['ConnectionStatusReason']) # And NoReply will do as “it crashed”. assertEquals(cs.DBUS_ERROR_NO_REPLY, changed['ConnectionError']) if __name__ == '__main__': exec_test(test)
assertEquals( { 'password': '******', 'account': '*****@*****.**', 'snakes': 23 }, account.Properties.Get(cs.ACCOUNT, 'Parameters')) # Delete the account assert account_iface.Remove() is None account_event, account_manager_event = q.expect_many( EventPattern('dbus-signal', path=account_path, signal='Removed', interface=cs.ACCOUNT, args=[]), EventPattern('dbus-signal', path=cs.AM_PATH, signal='AccountRemoved', interface=cs.AM, args=[account_path]), ) # Check the account is correctly deleted assert not os.path.exists(old_key_file_name) assert not os.path.exists(newer_key_file_name) assert not os.path.exists(new_variant_file_name) if __name__ == '__main__': exec_test(test, {}, timeout=10, use_fake_accounts_service=False)
) assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname')) q.dbus_return(e.message, signature='') # If we set an empty nickname while connected, MC uses our normalized # name (identifier) instead. call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', '') _, _, e = q.expect_many( EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, args=[{'Nickname': params['account']}]), EventPattern('dbus-return', method='Set'), EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='SetAliases', args=[{ conn.self_handle: params['account'] }], handled=False) ) assertEquals(params['account'], account_props.Get(cs.ACCOUNT, 'Nickname')) q.dbus_return(e.message, signature='') def test_both(q, bus, mc): test(q, bus, mc, nickname='resiak') test(q, bus, mc, nickname='*****@*****.**') test(q, bus, mc, nickname='') if __name__ == '__main__': exec_test(test_both, {})
# If we set an empty nickname while connected, MC uses our normalized # name (identifier) instead. call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', '') _, _, e = q.expect_many( EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, args=[{ 'Nickname': params['account'] }]), EventPattern('dbus-return', method='Set'), EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='SetAliases', args=[{ conn.self_handle: params['account'] }], handled=False)) assertEquals(params['account'], account_props.Get(cs.ACCOUNT, 'Nickname')) q.dbus_return(e.message, signature='') def test_both(q, bus, mc): test(q, bus, mc, nickname='resiak') test(q, bus, mc, nickname='*****@*****.**') test(q, bus, mc, nickname='') if __name__ == '__main__': exec_test(test_both, {})
# Test for a former default account storage backend: # ~/.mission-control/accounts.cfg, as used in MC 5.0 to 5.13.1 # # Copyright (C) 2009-2010 Nokia Corporation # Copyright (C) 2009-2014 Collabora Ltd. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA from storage_helper import test_keyfile from mctest import exec_test def test_5_12(q, bus, mc): test_keyfile(q, bus, mc, '5.12') if __name__ == '__main__': exec_test(test_5_12, {}, preload_mc=False, use_fake_accounts_service=False)
# Time passes. A channel is returned. channel_immutable = dbus.Dictionary(request) channel_immutable[cs.CHANNEL + '.InitiatorID'] = conn.self_ident channel_immutable[cs.CHANNEL + '.InitiatorHandle'] = conn.self_handle channel_immutable[cs.CHANNEL + '.Requested'] = True channel_immutable[cs.CHANNEL + '.Interfaces'] = \ dbus.Array([], signature='s') channel_immutable[cs.CHANNEL + '.TargetHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel = SimulatedChannel(conn, channel_immutable) # this order of events is guaranteed by telepathy-spec (since 0.17.14) q.dbus_return(cm_request_call.message, channel.object_path, channel.immutable, signature='oa{sv}') channel.announce() # there's no handler, so it gets shot down q.expect('dbus-method-call', path=channel.object_path, method='Close', handled=True) if __name__ == '__main__': exec_test(test, {})
# clean up the new connection when it does, rather than trying to sign it # in. connect_event = [ EventPattern('dbus-method-call', method='Connect'), ] q.forbid_events(connect_event) mc.connectivity.go_offline() # Make sure that MC has noticed that the network connection has gone away. sync_connectivity_state(mc) conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', account.object_path.split('/')[-1], 'myself') q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so') q.expect('dbus-method-call', method='Disconnect') # So now the user gives up and sets their RequestedPresence to offline. # Because this account does not ConnectAutomatically, if the network # connection comes back up the account should not be brought back online. q.forbid_events(request_connection_event) account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) mc.connectivity.go_online() # Make sure MC has noticed that the network connection has come back. sync_connectivity_state(mc) if __name__ == '__main__': exec_test(test, initially_online=False)