[Telepathy-commits] [telepathy-mission-control/master] Twisted tests: Add a test for accounts, run test in a private environment (MC_CHANDLERS_DIR, MC_MANAGER_DIR, MC_ACCOUNT_DIR), add a basic fake connection manager

Alban Crequy alban.crequy at collabora.co.uk
Thu Nov 20 07:43:10 PST 2008


---
 test/twisted/Makefile.am               |    1 +
 test/twisted/accounts/README           |    3 +
 test/twisted/chandlers/README          |    4 +
 test/twisted/fakecm.py                 |   32 +++++++++
 test/twisted/managers/README           |    4 +
 test/twisted/managers/fakecm.manager   |    7 ++
 test/twisted/test-account.py           |  119 ++++++++++++++++++++++++++++++++
 test/twisted/test-basic.py             |   45 +++++++-----
 test/twisted/tools/exec-with-log.sh.in |    5 ++
 9 files changed, 200 insertions(+), 20 deletions(-)
 create mode 100644 test/twisted/accounts/README
 create mode 100644 test/twisted/chandlers/README
 create mode 100644 test/twisted/fakecm.py
 create mode 100644 test/twisted/managers/README
 create mode 100644 test/twisted/managers/fakecm.manager
 create mode 100644 test/twisted/test-account.py

diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 021fa3b..14b5fc7 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -1,6 +1,7 @@
 TWISTED_TESTS =
 
 TWISTED_BASIC_TESTS = \
+        test-account.py \
         test-basic.py
 
 TESTS =
diff --git a/test/twisted/accounts/README b/test/twisted/accounts/README
new file mode 100644
index 0000000..a8b118f
--- /dev/null
+++ b/test/twisted/accounts/README
@@ -0,0 +1,3 @@
+Directory for twisted test to write the accounts.cfg file. $MC_ACCOUNT_DIR is
+set to this directory in the twisted environment.
+
diff --git a/test/twisted/chandlers/README b/test/twisted/chandlers/README
new file mode 100644
index 0000000..2980ceb
--- /dev/null
+++ b/test/twisted/chandlers/README
@@ -0,0 +1,4 @@
+This directory contains .chandler files used by Mission Control when it is run
+by twisted test. $MC_CHANDLERS_DIR is set to this directory in the twisted
+environment.
+
diff --git a/test/twisted/fakecm.py b/test/twisted/fakecm.py
new file mode 100644
index 0000000..17d9d7d
--- /dev/null
+++ b/test/twisted/fakecm.py
@@ -0,0 +1,32 @@
+import dbus
+import dbus.service
+from servicetest import Event
+
+cm_iface = "org.freedesktop.Telepathy.ConnectionManager"
+class FakeCM(dbus.service.Object):
+    def __init__(self, object_path, q, bus, nameref):
+        self.q = q
+        # keep a reference on nameref, otherwise, the name will be lost!
+        self.nameref = nameref 
+        dbus.service.Object.__init__(self, bus, object_path)
+
+    @dbus.service.method(dbus_interface=cm_iface,
+                         in_signature='v', out_signature='s')
+    def StringifyVariant(self, variant):
+        print "StringifyVariant called"
+        self.q.append(Event('dbus-method-call', name="StringifyVariant"))
+        return str(variant)
+
+    @dbus.service.method(dbus_interface=cm_iface,
+                         in_signature='s', out_signature='a(susv)')
+    def GetParameters(self, protocol):
+        self.q.append(Event('dbus-method-call', name="GetParameters",
+                    arg=protocol))
+        return []
+
+def start_fake_connection_manager(q, bus, bus_name, object_path):
+    nameref = dbus.service.BusName(bus_name, bus=bus)
+    cm = FakeCM(object_path, q, bus, nameref)
+    return cm
+
+
diff --git a/test/twisted/managers/README b/test/twisted/managers/README
new file mode 100644
index 0000000..d77437c
--- /dev/null
+++ b/test/twisted/managers/README
@@ -0,0 +1,4 @@
+This directory contains .manager files used by Mission Control when it is run
+by twisted test. $MC_MANAGER_DIR is set to this directory in the twisted
+environment.
+
diff --git a/test/twisted/managers/fakecm.manager b/test/twisted/managers/fakecm.manager
new file mode 100644
index 0000000..60a45cf
--- /dev/null
+++ b/test/twisted/managers/fakecm.manager
@@ -0,0 +1,7 @@
+[ConnectionManager]
+BusName=com.example.FakeCM
+ObjectPath=/com/example/FakeCM/ConnectionManager
+
+[Protocol fakeprotocol]
+param-nickname=s
+
diff --git a/test/twisted/test-account.py b/test/twisted/test-account.py
new file mode 100644
index 0000000..464e083
--- /dev/null
+++ b/test/twisted/test-account.py
@@ -0,0 +1,119 @@
+import dbus
+
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
+from fakecm import start_fake_connection_manager
+from mctest import exec_test
+
+FakeCM_bus_name = "com.example.FakeCM"
+ConnectionManager_object_path = "/com/example/FakeCM/ConnectionManager"
+
+
+def test(q, bus, mc):
+    # Get the AccountManager interface
+    account_manager = bus.get_object(
+        tp_name_prefix + '.AccountManager',
+        tp_path_prefix + '/AccountManager')
+    account_manager_iface = dbus.Interface(account_manager,
+            'org.freedesktop.Telepathy.AccountManager')
+
+    # Introspect AccountManager for debugging purpose
+    account_manager_introspected = account_manager.Introspect(
+            dbus_interface='org.freedesktop.DBus.Introspectable')
+    #print account_manager_introspected
+
+    # Check AccountManager has D-Bus property interface
+    properties = account_manager.GetAll(
+            'org.freedesktop.Telepathy.AccountManager',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert properties is not None
+    assert properties.get('Interfaces') == [
+            'org.freedesktop.Telepathy.AccountManager',
+            'com.nokia.AccountManager.Interface.Query',
+            'org.freedesktop.Telepathy.AccountManager.Interface.Creation.DRAFT'
+        ], properties.get('Interfaces')
+    assert properties.get('ValidAccounts') == [], \
+        properties.get('ValidAccounts')
+    assert properties.get('InvalidAccounts') == [], \
+        properties.get('InvalidAccounts')
+
+    # Create an account
+    params = dbus.Dictionary({"nickname": "fakenick"}, signature='sv')
+    account_path = account_manager_iface.CreateAccount(
+            'fakecm', # Connection_Manager
+            'fakeprotocol', # Protocol
+            'fakeaccount', #Display_Name
+            params, # Parameters
+            )
+    assert account_path is not None
+
+    # Check the account is correctly created
+    properties = account_manager.GetAll(
+            'org.freedesktop.Telepathy.AccountManager',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert properties is not None
+    assert properties.get('ValidAccounts') == [account_path], properties
+    assert properties.get('InvalidAccounts') == [], properties
+
+    # Get the Account interface
+    account = bus.get_object(
+        tp_name_prefix + '.AccountManager',
+        account_path)
+    account_iface = dbus.Interface(account,
+            'org.freedesktop.Telepathy.Account')
+    # Introspect Account for debugging purpose
+    account_introspected = account.Introspect(
+            dbus_interface='org.freedesktop.DBus.Introspectable')
+    #print account_introspected
+
+    # Check Account has D-Bus property interface
+    properties = account.GetAll(
+            'org.freedesktop.Telepathy.Account',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert properties is not None
+    assert 'org.freedesktop.Telepathy.Account' \
+        in properties.get('Interfaces'), properties.get('Interfaces')
+    assert 'org.freedesktop.Telepathy.Account.Interface.Avatar' \
+        in properties.get('Interfaces'), properties.get('Interfaces')
+    assert 'org.freedesktop.Telepathy.Account.Interface.Compat' \
+        in properties.get('Interfaces'), properties.get('Interfaces')
+    assert 'com.nokia.Account.Interface.Conditions' \
+        in properties.get('Interfaces'), properties.get('Interfaces')
+    assert properties.get('DisplayName') == 'fakeaccount', \
+        properties.get('DisplayName')
+    assert properties.get('Icon') == '', properties.get('Icon')
+    assert properties.get('Valid') == True, properties.get('Valid')
+    assert properties.get('Enabled') == False, properties.get('Enabled')
+    #assert properties.get('Nickname') == 'fakenick', properties.get('Nickname')
+    assert properties.get('Parameters') == params, properties.get('Parameters')
+    assert properties.get('Connection') == '', properties.get('Connection')
+    assert properties.get('NormalizedName') == '', \
+        properties.get('NormalizedName')
+
+    # Delete the account
+    assert account_iface.Remove() is None
+    account_event, account_manager_event = q.expect_many(
+        EventPattern('dbus-signal',
+            path=account_path,
+            signal='Removed',
+            interface='org.freedesktop.Telepathy.Account',
+            args=[]
+            ),
+        EventPattern('dbus-signal',
+            path=tp_path_prefix + '/AccountManager',
+            signal='AccountRemoved',
+            interface='org.freedesktop.Telepathy.AccountManager',
+            args=[account_path]
+            ),
+        )
+
+    # Check the account is correctly deleted
+    properties = account_manager.GetAll(
+            'org.freedesktop.Telepathy.AccountManager',
+            dbus_interface='org.freedesktop.DBus.Properties')
+    assert properties is not None
+    assert properties.get('ValidAccounts') == [], properties
+    assert properties.get('InvalidAccounts') == [], properties
+
+
+if __name__ == '__main__':
+    exec_test(test, {})
diff --git a/test/twisted/test-basic.py b/test/twisted/test-basic.py
index 40febc2..79b2f89 100644
--- a/test/twisted/test-basic.py
+++ b/test/twisted/test-basic.py
@@ -1,19 +1,22 @@
 import dbus
 
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
+from fakecm import start_fake_connection_manager
 from mctest import exec_test
 
+FakeCM_bus_name = "com.example.FakeCM"
+ConnectionManager_object_path = "/com/example/FakeCM/ConnectionManager"
+
+
 def test(q, bus, mc):
-    # Introspect for debugging purpose
+    start_fake_connection_manager(q, bus, FakeCM_bus_name,
+            ConnectionManager_object_path)
+    
+    # Introspect the old iface for debugging purpose
     mc_introspected = mc.Introspect(
             dbus_interface='org.freedesktop.DBus.Introspectable')
     #print mc_introspected
 
-    # Check MC has D-Bus property interface
-    properties = mc.GetAll(
-            'org.freedesktop.Telepathy.AccountManager',
-            dbus_interface='org.freedesktop.DBus.Properties')
-    assert properties is not None
-
     # Check the old iface
     old_iface = dbus.Interface(mc, 'org.freedesktop.Telepathy.MissionControl')
     arg0 = old_iface.GetOnlineConnections()
@@ -21,19 +24,21 @@ def test(q, bus, mc):
     arg0 = old_iface.GetPresence()
     assert arg0 == 0, arg0
 
-    # Check MC has AccountManager interface
-    account_manager_iface = dbus.Interface(mc,
-            'org.freedesktop.Telepathy.AccountManager')
-
-    ## Not yet implemented in MC
-    #params = dbus.Dictionary({}, signature='sv')
-    #account_name = account_manager_iface.CreateAccount(
-    #        'salut', # Connection_Manager
-    #        'local-xmpp', # Protocol
-    #        'mc_test', #Display_Name
-    #        params, # Parameters
-    #        )
-    #assert account_name is not None
+    ## Test the fake connection manager (test the test). The fake connection
+    ## manager aims to be used by Mission Control
+    fake_cm = bus.get_object(FakeCM_bus_name, ConnectionManager_object_path)
+
+    def reply_handler_cb(dummy):
+        print "ok: " + str(dummy)
+    def error_handler_cb(dummy):
+        print "error: " + str(dummy)
+
+    fake_cm.GetParameters("awrty", reply_handler=reply_handler_cb,
+            error_handler=error_handler_cb,
+            dbus_interface="org.freedesktop.Telepathy.ConnectionManager")
+    print "method called"
+    e = q.expect('dbus-method-call')
+    print e.name
 
 if __name__ == '__main__':
     exec_test(test, {})
diff --git a/test/twisted/tools/exec-with-log.sh.in b/test/twisted/tools/exec-with-log.sh.in
index dbda4bd..e10c197 100644
--- a/test/twisted/tools/exec-with-log.sh.in
+++ b/test/twisted/tools/exec-with-log.sh.in
@@ -3,6 +3,11 @@
 cd "@abs_top_builddir@/test/twisted/tools"
 
 export MC_DEBUG=2
+export MC_CHANDLERS_DIR="@abs_top_builddir@/test/twisted/chandlers"
+export MC_MANAGER_DIR="@abs_top_builddir@/test/twisted/managers"
+export MC_ACCOUNT_DIR="@abs_top_builddir@/test/twisted/accounts"
+#export MC_PROFILE_DIR=
+
 ulimit -c unlimited
 exec > missioncontrol-testing.log 2>&1
 
-- 
1.5.6.5




More information about the Telepathy-commits mailing list