From b0e8d9654693b457da81f21fc4816db7747f3138 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 5 Oct 2012 17:53:34 +0100 Subject: [PATCH 1/2] Emulate the Aliasing interface a little more realistically --- tests/twisted/account-manager/irc.py | 14 +++++--------- tests/twisted/account-manager/nickname.py | 4 +--- tests/twisted/mctest.py | 26 +++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/tests/twisted/account-manager/irc.py b/tests/twisted/account-manager/irc.py index eb79728..36bd283 100644 --- a/tests/twisted/account-manager/irc.py +++ b/tests/twisted/account-manager/irc.py @@ -49,7 +49,7 @@ def test(q, bus, mc): expect_after_connect = [ EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='GetAliases', - handled=False), + handled=True), EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='SetAliases', handled=False), @@ -61,8 +61,6 @@ def test(q, bus, mc): self_ident=params['account']) assert get_aliases.args[0] == [ conn.self_handle ] - q.dbus_return(get_aliases.message, { conn.self_handle: 'brucewayne' }, - signature='a{us}') assert set_aliases.args[0] == { conn.self_handle: 'BruceWayne' } q.dbus_return(set_aliases.message, signature='') @@ -74,18 +72,17 @@ def test(q, bus, mc): # Another client changes our alias remotely, but because this is IRC, # that manifests itself as a handle change conn.change_self_ident('thebatman') + conn.change_self_alias('TheBatman') get_aliases, _ = q.expect_many( EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, - method='GetAliases', handled=False), + method='GetAliases', handled=True), EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, predicate=(lambda e: e.args[0].get('NormalizedName') == 'thebatman')), ) assert get_aliases.args[0] == [ conn.self_handle ] - q.dbus_return(get_aliases.message, { conn.self_handle: 'TheBatman' }, - signature='a{us}') q.expect('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, args=[{'Nickname': 'TheBatman'}]) @@ -107,20 +104,19 @@ def test(q, bus, mc): ) assertEquals('BruceWayne', account_props.Get(cs.ACCOUNT, 'Nickname')) conn.change_self_ident('brucewayne') + conn.change_self_alias('BruceWayne') q.dbus_return(e.message, signature='') # In response to the self-handle change, we check our nickname again get_aliases, _ = q.expect_many( EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, - method='GetAliases', handled=False), + method='GetAliases', handled=True), EventPattern('dbus-signal', path=account.object_path, signal='AccountPropertyChanged', interface=cs.ACCOUNT, predicate=(lambda e: e.args[0].get('NormalizedName') == 'brucewayne')), ) assert get_aliases.args[0] == [ conn.self_handle ] - q.dbus_return(get_aliases.message, { conn.self_handle: 'BruceWayne' }, - signature='a{us}') forbidden = [EventPattern('dbus-signal', signal='AccountPropertyChanged', predicate=lambda e: 'Nickname' in e.args[0])] diff --git a/tests/twisted/account-manager/nickname.py b/tests/twisted/account-manager/nickname.py index 6060f26..5ca8708 100644 --- a/tests/twisted/account-manager/nickname.py +++ b/tests/twisted/account-manager/nickname.py @@ -54,7 +54,7 @@ def test(q, bus, mc, trivial_nickname=False): expect_after_connect = [ EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING, method='GetAliases', - handled=False), + handled=True), ] forbidden = [] @@ -74,8 +74,6 @@ def test(q, bus, mc, trivial_nickname=False): 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}') if trivial_nickname: assertLength(2, results) diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index ead5412..c1577cc 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -202,12 +202,17 @@ class SimulatedConnection(object): return self._last_handle def __init__(self, q, bus, cmname, protocol, account_part, self_ident, + self_alias=None, implement_get_interfaces=True, has_requests=True, has_presence=False, has_aliasing=False, has_avatars=False, - avatars_persist=True, extra_interfaces=[], has_hidden=False): + avatars_persist=True, extra_interfaces=[], has_hidden=False, + implement_get_aliases=True): self.q = q self.bus = bus + if self_alias is None: + self_alias = self_ident + self.bus_name = '.'.join([cs.tp_name_prefix, 'Connection', cmname, protocol.replace('-', '_'), account_part]) self._bus_name_ref = dbus.service.BusName(self.bus_name, self.bus) @@ -219,6 +224,7 @@ class SimulatedConnection(object): self.status = cs.CONN_STATUS_DISCONNECTED self.reason = cs.CONN_STATUS_CONNECTING self.self_ident = self_ident + self.self_alias = self_alias self.self_handle = self.ensure_handle(cs.HT_CONTACT, self_ident) self.channels = [] self.has_requests = has_requests @@ -313,6 +319,11 @@ class SimulatedConnection(object): method='GetAliasFlags', args=[]) + if implement_get_aliases: + q.add_dbus_method_impl(self.GetAliases, + path=self.object_path, + interface=cs.CONN_IFACE_ALIASING, method='GetAliases') + if has_avatars: q.add_dbus_method_impl(self.GetAvatarRequirements, path=self.object_path, interface=cs.CONN_IFACE_AVATARS, @@ -350,6 +361,12 @@ class SimulatedConnection(object): self.q.dbus_emit(self.object_path, cs.CONN, 'SelfHandleChanged', self.self_handle, signature='u') + def change_self_alias(self, alias): + self.self_alias = alias + self.q.dbus_emit(self.object_path, cs.CONN_IFACE_ALIASING, + 'AliasesChanged', [(self.self_handle, self.self_alias)], + signature='a(us)') + def release_name(self): del self._bus_name_ref @@ -368,6 +385,13 @@ class SimulatedConnection(object): def GetAliasFlags(self, e): self.q.dbus_return(e.message, 0, signature='u') + def GetAliases(self, e): + ret = dbus.Dictionary(signature='us') + if self.self_handle in e.args[0]: + ret[self.self_handle] = self.self_alias + + self.q.dbus_return(e.message, ret, signature='a{us}') + # mostly for the UI's benefit; for now hard-code the requirements from XMPP def GetAvatarRequirements(self, e): self.q.dbus_return(e.message, ['image/jpeg'], 0, 0, 96, 96, 8192, -- 1.7.10.4