From a4355bb2eb2a682a4c1298c01683cffb4e42a666 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 9 Oct 2012 11:10:12 +0100 Subject: [PATCH 3/7] nickname test: test what happens when we set an empty nickname --- tests/twisted/account-manager/nickname.py | 70 ++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/tests/twisted/account-manager/nickname.py b/tests/twisted/account-manager/nickname.py index 5ca8708..5a1c465 100644 --- a/tests/twisted/account-manager/nickname.py +++ b/tests/twisted/account-manager/nickname.py @@ -25,7 +25,7 @@ from servicetest import (EventPattern, tp_name_prefix, tp_path_prefix, from mctest import exec_test, create_fakecm_account, enable_fakecm_account import constants as cs -def test(q, bus, mc, trivial_nickname=False): +def test(q, bus, mc, nickname): params = dbus.Dictionary({"account": "wjt@example.com", "password": "secrecy"}, signature='sv') (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params) @@ -33,21 +33,19 @@ def test(q, bus, mc, trivial_nickname=False): 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', nickname) - q.expect_many( - EventPattern('dbus-signal', - path=account.object_path, - signal='AccountPropertyChanged', - interface=cs.ACCOUNT, - args=[{'Nickname': nickname}]), - EventPattern('dbus-return', method='Set'), - ) + if nickname == '': + q.expect('dbus-return', method='Set') + else: + q.expect_many( + EventPattern('dbus-signal', + path=account.object_path, + signal='AccountPropertyChanged', + interface=cs.ACCOUNT, + args=[{'Nickname': nickname}]), + EventPattern('dbus-return', method='Set'), + ) assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname')) # OK, let's go online @@ -58,9 +56,17 @@ def test(q, bus, mc, trivial_nickname=False): ] forbidden = [] - if trivial_nickname: + if nickname == params['account'] or nickname == '': forbidden.append(EventPattern('dbus-method-call', method='SetAliases')) q.forbid_events(forbidden) + + if nickname == '': + expect_after_connect.append(EventPattern('dbus-signal', + path=account.object_path, + signal='AccountPropertyChanged', + interface=cs.ACCOUNT, + predicate=(lambda e: + e.args[0].get('Nickname') == params['account']))) else: expect_after_connect.append(EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='SetAliases', @@ -75,12 +81,14 @@ def test(q, bus, mc, trivial_nickname=False): get_aliases = results[1] assert get_aliases.args[0] == [ conn.self_handle ] - if trivial_nickname: + if nickname == params['account']: assertLength(2, results) + elif nickname == '': + assertLength(3, results) else: assertLength(3, results) set_aliases = results[2] - assert set_aliases.args[0] == { conn.self_handle: 'resiak' } + assert set_aliases.args[0] == { conn.self_handle: nickname } q.dbus_return(set_aliases.message, signature='') if forbidden: @@ -115,13 +123,13 @@ def test(q, bus, mc, trivial_nickname=False): # 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) + params['account']) _, _, e = q.expect_many( EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, - args=[{'Nickname': nickname}]), + args=[{'Nickname': params['account']}]), EventPattern('dbus-return', method='Set'), EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='SetAliases', @@ -131,9 +139,29 @@ def test(q, bus, mc, trivial_nickname=False): assertEquals(nickname, account_props.Get(cs.ACCOUNT, 'Nickname')) q.dbus_return(e.message, signature='') + # If we set an empty nickname while connected, MC currently does use it + # (??? this is pretty weird) + 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': ''}]), + EventPattern('dbus-return', method='Set'), + EventPattern('dbus-method-call', + interface=cs.CONN_IFACE_ALIASING, method='SetAliases', + args=[{ conn.self_handle: '' }], + handled=False) + ) + assertEquals('', 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) + test(q, bus, mc, nickname='resiak') + test(q, bus, mc, nickname='wjt@example.com') + test(q, bus, mc, nickname='') if __name__ == '__main__': exec_test(test_both, {}) -- 1.7.10.4