From bfdc51559a0b5ce0959ed87a92ebf63fa37150b8 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 5 Oct 2012 12:42:39 +0100 Subject: [PATCH 5/8] nickname test: verify that a trivial nickname is not set on connect --- tests/twisted/account-manager/nickname.py | 84 ++++++++++++++++++++++------- tests/twisted/mctest.py | 5 +- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/tests/twisted/account-manager/nickname.py b/tests/twisted/account-manager/nickname.py index 8e2fe79..6060f26 100644 --- a/tests/twisted/account-manager/nickname.py +++ b/tests/twisted/account-manager/nickname.py @@ -20,12 +20,12 @@ import dbus import dbus import dbus.service -from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ - call_async +from servicetest import (EventPattern, tp_name_prefix, tp_path_prefix, + call_async, assertEquals, assertLength, sync_dbus) from mctest import exec_test, create_fakecm_account, enable_fakecm_account import constants as cs -def test(q, bus, mc): +def test(q, bus, mc, trivial_nickname=False): params = dbus.Dictionary({"account": "wjt@example.com", "password": "secrecy"}, signature='sv') (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params) @@ -33,36 +33,61 @@ def test(q, bus, mc): account_iface = dbus.Interface(account, cs.ACCOUNT) account_props = dbus.Interface(account, cs.PROPERTIES_IFACE) + if trivial_nickname: + nickname = params['account'] + else: + nickname = 'resiak' + call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', - 'resiak') + nickname) q.expect_many( EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, - args=[{'Nickname': 'resiak'}]), + args=[{'Nickname': nickname}]), EventPattern('dbus-return', method='Set'), ) - assert account_props.Get(cs.ACCOUNT, 'Nickname') == 'resiak' + assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname')) # OK, let's go online - conn, get_aliases, set_aliases = enable_fakecm_account(q, bus, mc, + expect_after_connect = [ + EventPattern('dbus-method-call', + interface=cs.CONN_IFACE_ALIASING, method='GetAliases', + handled=False), + ] + forbidden = [] + + if trivial_nickname: + forbidden.append(EventPattern('dbus-method-call', method='SetAliases')) + q.forbid_events(forbidden) + else: + expect_after_connect.append(EventPattern('dbus-method-call', + interface=cs.CONN_IFACE_ALIASING, method='SetAliases', + handled=False)) + + results = enable_fakecm_account(q, bus, mc, account, params, has_aliasing=True, - expect_after_connect=[ - EventPattern('dbus-method-call', - interface=cs.CONN_IFACE_ALIASING, method='GetAliases', - handled=False), - EventPattern('dbus-method-call', - interface=cs.CONN_IFACE_ALIASING, method='SetAliases', - handled=False), - ]) + expect_after_connect=expect_after_connect, + self_ident=params['account']) + conn = results[0] + get_aliases = results[1] assert get_aliases.args[0] == [ conn.self_handle ] q.dbus_return(get_aliases.message, { conn.self_handle: 'wjt@example.com' }, signature='a{us}') - assert set_aliases.args[0] == { conn.self_handle: 'resiak' } - q.dbus_return(set_aliases.message, signature='') + if trivial_nickname: + assertLength(2, results) + else: + assertLength(3, results) + set_aliases = results[2] + assert set_aliases.args[0] == { conn.self_handle: 'resiak' } + q.dbus_return(set_aliases.message, signature='') + + if forbidden: + sync_dbus(bus, q, mc) + q.unforbid_events(forbidden) # Change alias after going online call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', @@ -89,5 +114,28 @@ def test(q, bus, mc): signal='AccountPropertyChanged', interface=cs.ACCOUNT, args=[{'Nickname': 'wjt'}]) + # If we set a trivial nickname while connected, MC does use it + nickname = params['account'] + call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname', + nickname) + _, _, e = q.expect_many( + EventPattern('dbus-signal', + path=account.object_path, + signal='AccountPropertyChanged', + interface=cs.ACCOUNT, + args=[{'Nickname': nickname}]), + 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(nickname, account_props.Get(cs.ACCOUNT, 'Nickname')) + q.dbus_return(e.message, signature='') + +def test_both(q, bus, mc): + test(q, bus, mc, trivial_nickname=False) + test(q, bus, mc, trivial_nickname=True) + if __name__ == '__main__': - exec_test(test, {}) + exec_test(test_both, {}) diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index e6eff4a..68dde0d 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -947,7 +947,8 @@ def expect_fakecm_connection(q, bus, mc, account, expected_params, has_avatars=False, avatars_persist=True, extra_interfaces=[], expect_before_connect=(), expect_after_connect=(), - has_hidden=False): + has_hidden=False, + self_ident='myself'): # make (safely) mutable copies expect_before_connect = list(expect_before_connect) expect_after_connect = list(expect_after_connect) @@ -961,7 +962,7 @@ def expect_fakecm_connection(q, bus, mc, account, expected_params, conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', account.object_path.split('/')[-1], - 'myself', has_requests=has_requests, has_presence=has_presence, + self_ident, has_requests=has_requests, has_presence=has_presence, has_aliasing=has_aliasing, has_avatars=has_avatars, avatars_persist=avatars_persist, extra_interfaces=extra_interfaces, has_hidden=has_hidden) -- 1.7.10.4