[telepathy-mission-control/master] mctest: factor out code to create an account and put it online

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Apr 1 03:26:23 PDT 2009


---
 test/twisted/mctest.py       |   94 ++++++++++++++++++++++++++++++++++++++++++
 test/twisted/test-account.py |   31 +------------
 test/twisted/test-connect.py |   27 ++----------
 3 files changed, 101 insertions(+), 51 deletions(-)

diff --git a/test/twisted/mctest.py b/test/twisted/mctest.py
index 7fba030..d43dced 100644
--- a/test/twisted/mctest.py
+++ b/test/twisted/mctest.py
@@ -176,3 +176,97 @@ class SimulatedConnection(object):
 
     def GetSelfHandle(self, e):
         self.q.dbus_return(e.message, self.self_handle, signature='u')
+
+def aasv(x):
+    return dbus.Array([dbus.Dictionary(d, signature='sv') for d in x],
+            signature='a{sv}')
+
+def create_fakecm_account(q, bus, mc, params):
+    """Create a fake connection manager and an account that uses it.
+    """
+    cm_name_ref = dbus.service.BusName(
+            cs.tp_name_prefix + '.ConnectionManager.fakecm', bus=bus)
+
+    # Get the AccountManager interface
+    account_manager = bus.get_object(cs.AM, cs.AM_PATH)
+    account_manager_iface = dbus.Interface(account_manager, cs.AM)
+
+    # Create an account
+    servicetest.call_async(q, account_manager_iface, 'CreateAccount',
+            'fakecm', # Connection_Manager
+            'fakeprotocol', # Protocol
+            'fakeaccount', #Display_Name
+            params, # Parameters
+            )
+    # The spec has no order guarantee here.
+    # FIXME: MC ought to also introspect the CM and find out that the params
+    # are in fact sufficient
+
+    a_signal, am_signal, ret = q.expect_many(
+            servicetest.EventPattern('dbus-signal',
+                signal='AccountPropertyChanged', interface=cs.ACCOUNT),
+            servicetest.EventPattern('dbus-signal', path=cs.AM_PATH,
+                signal='AccountValidityChanged', interface=cs.AM),
+            servicetest.EventPattern('dbus-return', method='CreateAccount'),
+            )
+    account_path = ret.value[0]
+    assert am_signal.args == [account_path, True], am_signal.args
+    assert a_signal.args[0]['Valid'] == True, a_signal.args
+
+    assert account_path is not None
+
+    # Get the Account interface
+    account = bus.get_object(
+        cs.tp_name_prefix + '.AccountManager',
+        account_path)
+    account_iface = dbus.Interface(account, cs.ACCOUNT)
+    account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
+    # Introspect Account for debugging purpose
+    account_introspected = account.Introspect(
+            dbus_interface=cs.INTROSPECTABLE_IFACE)
+    #print account_introspected
+
+    return (cm_name_ref, account)
+
+def enable_fakecm_account(q, bus, mc, account, expected_params):
+    # Enable the account
+    account.Set(cs.ACCOUNT, 'Enabled', True,
+            dbus_interface=cs.PROPERTIES_IFACE)
+
+    requested_presence = dbus.Struct((dbus.UInt32(2L),
+        dbus.String(u'available'), dbus.String(u'')))
+    account.Set(cs.ACCOUNT,
+            'RequestedPresence', requested_presence,
+            dbus_interface=cs.PROPERTIES_IFACE)
+
+    e = q.expect('dbus-method-call', method='RequestConnection',
+            args=['fakeprotocol', expected_params],
+            destination=cs.tp_name_prefix + '.ConnectionManager.fakecm',
+            path=cs.tp_path_prefix + '/ConnectionManager/fakecm',
+            interface=cs.tp_name_prefix + '.ConnectionManager',
+            handled=False)
+
+    conn = SimulatedConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+            'myself')
+
+    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)
+    conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+    q.expect_many(
+            servicetest.EventPattern('dbus-method-call',
+                interface=cs.PROPERTIES_IFACE, method='GetAll',
+                args=[cs.CONN_IFACE_REQUESTS],
+                path=conn.object_path, handled=True),
+            )
+
+    # this secretly indicates that the TpConnection is ready
+    # FIXME: find a better way to determine that the account is ready for use
+    e = q.expect('dbus-signal',
+            interface=cs.ACCOUNT, signal='AccountPropertyChanged',
+            path=account.object_path,
+            args=[{'NormalizedName': 'myself'}])
+
+    return conn
diff --git a/test/twisted/test-account.py b/test/twisted/test-account.py
index 3ededda..0108eaa 100644
--- a/test/twisted/test-account.py
+++ b/test/twisted/test-account.py
@@ -3,13 +3,10 @@ import dbus.service
 
 from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
         call_async
-from mctest import exec_test
+from mctest import exec_test, create_fakecm_account
 import constants as cs
 
 def test(q, bus, mc):
-    cm_name = dbus.service.BusName(
-            tp_name_prefix + '.ConnectionManager.fakecm', bus=bus)
-
     # Get the AccountManager interface
     account_manager = bus.get_object(cs.AM, cs.AM_PATH)
     account_manager_iface = dbus.Interface(account_manager, cs.AM)
@@ -33,29 +30,11 @@ def test(q, bus, mc):
     assert cs.AM_IFACE_CREATION_DRAFT in interfaces, interfaces
     assert cs.AM_IFACE_NOKIA_QUERY in interfaces, interfaces
 
-    # Create an account
     params = dbus.Dictionary({"account": "someguy at example.com",
         "password": "secrecy"}, signature='sv')
-    call_async(q, account_manager_iface, 'CreateAccount',
-            'fakecm', # Connection_Manager
-            'fakeprotocol', # Protocol
-            'fakeaccount', #Display_Name
-            params, # Parameters
-            )
-    # the spec has no order guarantee here
-
-    # FIXME: MC ought to introspect the CM and find out that the params are
-    # in fact sufficient
-
-    signal, ret = q.expect_many(
-            EventPattern('dbus-signal', path=cs.AM_PATH,
-                signal='AccountValidityChanged', interface=cs.AM),
-            EventPattern('dbus-return', method='CreateAccount'),
-            )
-    account_path = ret.value[0]
-    assert signal.args == [account_path, True], signal.args
-
-    assert account_path is not None
+    (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
+
+    account_path = account.__dbus_object_path__
 
     # Check the account is correctly created
     properties = account_manager.GetAll(cs.AM,
@@ -66,10 +45,6 @@ def test(q, bus, mc):
     assert isinstance(account_path, dbus.ObjectPath), repr(account_path)
     assert properties.get('InvalidAccounts') == [], properties
 
-    # Get the Account interface
-    account = bus.get_object(
-        tp_name_prefix + '.AccountManager',
-        account_path)
     account_iface = dbus.Interface(account, cs.ACCOUNT)
     account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
     # Introspect Account for debugging purpose
diff --git a/test/twisted/test-connect.py b/test/twisted/test-connect.py
index 97d5fad..d7d0765 100644
--- a/test/twisted/test-connect.py
+++ b/test/twisted/test-connect.py
@@ -2,7 +2,7 @@ import dbus
 import dbus.service
 
 from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
-from mctest import exec_test, SimulatedConnection
+from mctest import exec_test, SimulatedConnection, create_fakecm_account
 import constants as cs
 
 def test(q, bus, mc):
@@ -35,29 +35,10 @@ def test(q, bus, mc):
     q.dbus_return(e.message, dbus.Array([http_fixed_properties],
         signature='a{sv}', variant_level=1), signature='v')
 
-    # Get the AccountManager interface
-    account_manager = bus.get_object(cs.AM, cs.AM_PATH)
-    account_manager_iface = dbus.Interface(account_manager, cs.AM)
-
     # Create an account
     params = dbus.Dictionary({"account": "someguy at example.com",
         "password": "secrecy"}, signature='sv')
-    account_path = account_manager_iface.CreateAccount(
-            'fakecm', # Connection_Manager
-            'fakeprotocol', # Protocol
-            'fakeaccount', #Display_Name
-            params, # Parameters
-            )
-    assert account_path is not None
-
-    # Get the Account interface
-    account = bus.get_object(
-        tp_name_prefix + '.AccountManager',
-        account_path)
-    account_iface = dbus.Interface(account, cs.ACCOUNT)
-
-    # FIXME: MC ought to introspect the CM and find out that the params are
-    # in fact sufficient
+    (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
 
     # The account is initially valid but disabled
     assert not account.Get(cs.ACCOUNT, 'Enabled',
@@ -69,7 +50,7 @@ def test(q, bus, mc):
     account.Set(cs.ACCOUNT, 'Enabled', True,
             dbus_interface=cs.PROPERTIES_IFACE)
     q.expect('dbus-signal',
-            path=account_path,
+            path=account.object_path,
             signal='AccountPropertyChanged',
             interface=cs.ACCOUNT)
 
@@ -129,7 +110,7 @@ def test(q, bus, mc):
     # this secretly indicates that the TpConnection is ready
     e = q.expect('dbus-signal',
             interface=cs.ACCOUNT, signal='AccountPropertyChanged',
-            path=account_path,
+            path=account.object_path,
             args=[{'NormalizedName': 'myself'}])
 
     #e = q.expect('dbus-method-call', name='SetSelfCapabilities',
-- 
1.5.6.5




More information about the telepathy-commits mailing list