[Telepathy-commits] [telepathy-mission-control/master] Twisted tests: add test to set the status to online

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


---
 test/twisted/Makefile.am     |    3 +-
 test/twisted/fakecm.py       |   45 +++++++++++++++++++++++++-----
 test/twisted/test-connect.py |   61 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 9 deletions(-)
 create mode 100644 test/twisted/test-connect.py

diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 14b5fc7..4611147 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -2,7 +2,8 @@ TWISTED_TESTS =
 
 TWISTED_BASIC_TESTS = \
         test-account.py \
-        test-basic.py
+        test-basic.py \
+        test-connect.py
 
 TESTS =
 
diff --git a/test/twisted/fakecm.py b/test/twisted/fakecm.py
index 17d9d7d..5dfd6ce 100644
--- a/test/twisted/fakecm.py
+++ b/test/twisted/fakecm.py
@@ -1,29 +1,58 @@
 import dbus
 import dbus.service
 from servicetest import Event
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
 
 cm_iface = "org.freedesktop.Telepathy.ConnectionManager"
-class FakeCM(dbus.service.Object):
+conn_iface = "org.freedesktop.Telepathy.Connection"
+
+class FakeConn(dbus.service.Object):
     def __init__(self, object_path, q, bus, nameref):
+        self.object_path = object_path
         self.q = q
+        self.bus = bus
         # 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=conn_iface,
+                         in_signature='', out_signature='')
+    def Connect(self, protocol):
+        self.q.append(Event('dbus-method-call', name="Connect", obj=self))
+        return None
+
+class FakeCM(dbus.service.Object):
+    def __init__(self, object_path, q, bus, nameref):
+        self.object_path = object_path
+        self.q = q
+        self.bus = bus
+        # 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='s', out_signature='a(susv)')
     def GetParameters(self, protocol):
         self.q.append(Event('dbus-method-call', name="GetParameters",
-                    arg=protocol))
+                    protocol=protocol, obj=self))
         return []
 
+    @dbus.service.method(dbus_interface=cm_iface,
+                         in_signature='', out_signature='as')
+    def ListProtocols(self, protocol):
+        self.q.append(Event('dbus-method-call', name="ListProtocols", obj=self))
+        return ['fakeprotocol']
+
+    @dbus.service.method(dbus_interface=cm_iface,
+                         in_signature='sa{sv}', out_signature='so')
+    def RequestConnection(self, protocol, parameters):
+        conn_path = tp_path_prefix + "/Connection/fakecm/fakeprotocol/conn1"
+        conn = FakeConn(conn_path, self.q, self.bus, self.nameref)
+        self.q.append(Event('dbus-method-call', name="RequestConnection",
+                    protocol=protocol, parameters=parameters,
+                    conn=conn, obj=self))
+        return ['fakeprotocol', conn_path]
+
 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)
diff --git a/test/twisted/test-connect.py b/test/twisted/test-connect.py
new file mode 100644
index 0000000..979d38e
--- /dev/null
+++ b/test/twisted/test-connect.py
@@ -0,0 +1,61 @@
+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 = "org.freedesktop.Telepathy.ConnectionManager.fakecm"
+ConnectionManager_object_path = \
+    "/org/freedesktop/Telepathy/ConnectionManager/fakecm"
+
+
+def test(q, bus, mc):
+    start_fake_connection_manager(q, bus, FakeCM_bus_name,
+            ConnectionManager_object_path)
+    
+    # Check the old iface
+    old_iface = dbus.Interface(mc, 'org.freedesktop.Telepathy.MissionControl')
+    arg0 = old_iface.GetOnlineConnections()
+    assert arg0 == []
+    arg0 = old_iface.GetPresence()
+    assert arg0 == 0, arg0
+
+    # 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')
+
+    # 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
+
+    # Get the Account interface
+    account = bus.get_object(
+        tp_name_prefix + '.AccountManager',
+        account_path)
+    account_iface = dbus.Interface(account,
+            'org.freedesktop.Telepathy.Account')
+
+    # Enable the account
+    account.Set('org.freedesktop.Telepathy.Account',
+            'Enabled', True,
+            dbus_interface='org.freedesktop.DBus.Properties')
+
+    # Which value should I use?
+    # MC_PRESENCE_AVAILABLE == 2
+    # TP_CONNECTION_STATUS_CONNECTED == 0
+    old_iface.SetPresence(2, "Hello, everybody!")
+    e = q.expect('dbus-method-call', name='RequestConnection',
+            protocol='fakeprotocol')
+    assert e.parameters == params
+
+if __name__ == '__main__':
+    exec_test(test, {})
-- 
1.5.6.5




More information about the Telepathy-commits mailing list