telepathy-mission-control: Add a regression test for an IRC-like protocol

Simon McVittie smcv at kemper.freedesktop.org
Tue Oct 9 09:11:34 PDT 2012


Module: telepathy-mission-control
Branch: master
Commit: b543e87d5fcb65ef61516b4bf6c03cb4f27583b4
URL:    http://cgit.freedesktop.org/telepathy/telepathy-mission-control/commit/?id=b543e87d5fcb65ef61516b4bf6c03cb4f27583b4

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Fri Oct  5 13:45:58 2012 +0100

Add a regression test for an IRC-like protocol

IRC has plenty of oddities, but the one we're interested in here
is that your nickname and your unique identifier are inextricably linked.

---

 tests/twisted/Makefile.am            |    1 +
 tests/twisted/account-manager/irc.py |  127 ++++++++++++++++++++++++++++++++++
 tests/twisted/mctest.py              |    6 ++
 3 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index ac93146..2e46546 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -10,6 +10,7 @@ TWISTED_BASIC_TESTS = \
 	account-manager/create-with-properties.py \
 	account-manager/enable-auto-connect.py \
 	account-manager/enable.py \
+	account-manager/irc.py \
 	account-manager/nickname.py \
 	account-manager/param-types.py \
 	account-manager/presence.py \
diff --git a/tests/twisted/account-manager/irc.py b/tests/twisted/account-manager/irc.py
new file mode 100644
index 0000000..bebf091
--- /dev/null
+++ b/tests/twisted/account-manager/irc.py
@@ -0,0 +1,127 @@
+# encoding: utf-8
+#
+# Copyright © 2009 Nokia Corporation
+# Copyright © 2009-2012 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
+
+import dbus
+import dbus
+import dbus.service
+
+from servicetest import (EventPattern, call_async, assertEquals, sync_dbus)
+from mctest import (exec_test, create_fakecm_account, enable_fakecm_account)
+import constants as cs
+
+def test(q, bus, mc):
+    params = dbus.Dictionary({"account": "brucewayne",
+        "password": "secrecy"}, signature='sv')
+    (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
+
+    account_iface = dbus.Interface(account, cs.ACCOUNT)
+    account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
+
+    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname',
+            "BruceWayne")
+    q.expect_many(
+        EventPattern('dbus-signal',
+            path=account.object_path,
+            signal='AccountPropertyChanged',
+            interface=cs.ACCOUNT,
+            args=[{'Nickname': "BruceWayne"}]),
+        EventPattern('dbus-return', method='Set'),
+        )
+    assertEquals("BruceWayne", account_props.Get(cs.ACCOUNT, 'Nickname'))
+
+    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),
+            ]
+
+    conn, get_aliases, set_aliases = enable_fakecm_account(q, bus, mc,
+            account, params, has_aliasing=True,
+            expect_after_connect=expect_after_connect,
+            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='')
+
+    # Another client changes our alias remotely, but because this is IRC,
+    # that manifests itself as a handle change
+    conn.change_self_ident('thebatman')
+
+    get_aliases, _ = q.expect_many(
+        EventPattern('dbus-method-call', interface=cs.CONN_IFACE_ALIASING,
+            method='GetAliases', handled=False),
+        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'}])
+
+    # We change our nickname back
+    call_async(q, account_props, 'Set', cs.ACCOUNT, 'Nickname',
+            'BruceWayne')
+    _, _, e = q.expect_many(
+        EventPattern('dbus-signal',
+            path=account.object_path,
+            signal='AccountPropertyChanged',
+            interface=cs.ACCOUNT,
+            predicate=(lambda e: e.args[0].get('Nickname') == 'BruceWayne')),
+        EventPattern('dbus-return', method='Set'),
+        EventPattern('dbus-method-call',
+            interface=cs.CONN_IFACE_ALIASING, method='SetAliases',
+            args=[{ conn.self_handle: 'BruceWayne', }],
+            handled=False)
+        )
+    assertEquals('BruceWayne', account_props.Get(cs.ACCOUNT, 'Nickname'))
+    conn.change_self_ident('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),
+        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])]
+    q.forbid_events(forbidden)
+    sync_dbus(bus, q, mc)
+
+if __name__ == '__main__':
+    exec_test(test, {})
diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py
index 68dde0d..ead5412 100644
--- a/tests/twisted/mctest.py
+++ b/tests/twisted/mctest.py
@@ -344,6 +344,12 @@ class SimulatedConnection(object):
         self.presence = dbus.Struct((cs.PRESENCE_TYPE_OFFLINE, 'offline', ''),
                 signature='uss')
 
+    def change_self_ident(self, ident):
+        self.self_ident = ident
+        self.self_handle = self.ensure_handle(cs.HT_CONTACT, ident)
+        self.q.dbus_emit(self.object_path, cs.CONN, 'SelfHandleChanged',
+                self.self_handle, signature='u')
+
     def release_name(self):
         del self._bus_name_ref
 



More information about the telepathy-commits mailing list