[Telepathy-commits] [telepathy-mission-control/master] Test dispatcher: dispatch a tube channel
Alban Crequy
alban.crequy at collabora.co.uk
Thu Nov 20 09:21:10 PST 2008
---
test/twisted/fakeclient.py | 9 +++++++
test/twisted/fakecm.py | 55 +++++++++++++++++++++++++++++++++++++++++-
test/twisted/test-connect.py | 11 +++++++-
3 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/test/twisted/fakeclient.py b/test/twisted/fakeclient.py
index fee1258..93a85a0 100644
--- a/test/twisted/fakeclient.py
+++ b/test/twisted/fakeclient.py
@@ -64,6 +64,15 @@ class FakeClient(dbus.service.Object):
}, signature='sv')
return None
+ @dbus.service.method(dbus_interface=client_handler_iface,
+ in_signature='ooa(oa{sv})aot', out_signature='')
+ def HandleChannels(self, account, connection, channels,
+ requests_satisfied, user_action_time):
+ self.q.append(Event('dbus-method-call', name="HandleChannels",
+ obj=self, account=account, connection=connection,
+ channels=channels, requests_satisfied=requests_satisfied,
+ user_action_time=user_action_time))
+
def start_fake_client(q, bus, bus_name, object_path, caps):
nameref = dbus.service.BusName(bus_name, bus=bus)
client = FakeClient(object_path, q, bus, bus_name, nameref, caps)
diff --git a/test/twisted/fakecm.py b/test/twisted/fakecm.py
index 3c1fd9e..08472f8 100644
--- a/test/twisted/fakecm.py
+++ b/test/twisted/fakecm.py
@@ -3,10 +3,12 @@ import dbus.service
from servicetest import Event
from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
+properties_iface = "org.freedesktop.DBus.Properties"
cm_iface = "org.freedesktop.Telepathy.ConnectionManager"
conn_iface = "org.freedesktop.Telepathy.Connection"
caps_iface = \
"org.freedesktop.Telepathy.Connection.Interface.ContactCapabilities.DRAFT"
+requests_iface = "org.freedesktop.Telepathy.Connection.Interface.Requests"
class FakeConn(dbus.service.Object):
def __init__(self, object_path, q, bus, nameref):
@@ -16,6 +18,7 @@ class FakeConn(dbus.service.Object):
# keep a reference on nameref, otherwise, the name will be lost!
self.nameref = nameref
self.status = 2 # Connection_Status_Disconnected
+ self.channels = []
dbus.service.Object.__init__(self, bus, object_path)
# interface Connection
@@ -34,7 +37,7 @@ class FakeConn(dbus.service.Object):
def GetInterfaces(self):
self.q.append(Event('dbus-method-call', name="GetInterfaces",
obj=self, path=self.object_path))
- return dbus.Array([conn_iface, caps_iface])
+ return dbus.Array([conn_iface, caps_iface, requests_iface])
@dbus.service.method(dbus_interface=conn_iface,
in_signature='', out_signature='u')
@@ -72,6 +75,56 @@ class FakeConn(dbus.service.Object):
obj=self, path=self.object_path, caps=caps))
return None
+ @dbus.service.signal(dbus_interface=requests_iface,
+ signature='a(oa{sv})')
+ def NewChannels(self, array):
+ self.channels = self.channels + array
+
+ @dbus.service.signal(dbus_interface=conn_iface,
+ signature='osuub')
+ def NewChannel(self, object_path, channel_type, handle_type, handle,
+ suppress_handle):
+ pass
+
+ @dbus.service.method(dbus_interface=properties_iface,
+ in_signature='ss', out_signature='v')
+ def Get(self, interface_name, property_name):
+ self.q.append(Event('dbus-method-call', name="Get",
+ obj=self, interface_name=interface_name,
+ property_name=property_name))
+ if interface_name == requests_iface and \
+ property_name == "Channels":
+ return dbus.Array(self.channels, signature='(oa{sv})')
+ print "Error: interface_name=%s property_name=%s" % \
+ (interface_name, property_name)
+ return None
+
+ @dbus.service.method(dbus_interface=properties_iface,
+ in_signature='s', out_signature='a{sv}')
+ def GetAll(self, interface_name):
+ self.q.append(Event('dbus-method-call', name="GetAll",
+ obj=self, interface_name=interface_name))
+ if interface_name == conn_iface:
+ return dbus.Dictionary({
+ 'SelfHandle': 0L
+ }, signature='sv')
+ if interface_name == requests_iface:
+ return dbus.Dictionary({
+ 'Channels': dbus.Array(self.channels,
+ signature='(oa{sv})')
+ }, signature='sv')
+ return None
+
+ def new_incoming_channel(self, object_path, asv):
+ self.NewChannels(dbus.Array([(object_path, asv)],
+ signature='(oa{sv})'))
+ self.NewChannel(object_path,
+ asv['org.freedesktop.Telepathy.Channel.ChannelType'],
+ asv['org.freedesktop.Telepathy.Channel.TargetHandleType'],
+ asv['org.freedesktop.Telepathy.Channel.TargetHandle'],
+ False)
+
+
class FakeCM(dbus.service.Object):
def __init__(self, object_path, q, bus, bus_name, nameref):
self.object_path = object_path
diff --git a/test/twisted/test-connect.py b/test/twisted/test-connect.py
index d2e8a8c..1c8420c 100644
--- a/test/twisted/test-connect.py
+++ b/test/twisted/test-connect.py
@@ -27,7 +27,7 @@ def test(q, bus, mc):
}, signature='sv')
caps = dbus.Array([http_fixed_properties], signature='a{sv}')
- start_fake_client(q, bus, FakeClient_bus_name,
+ fake_client = start_fake_client(q, bus, FakeClient_bus_name,
Client_object_path, caps)
# Get the AccountManager interface
@@ -87,6 +87,7 @@ def test(q, bus, mc):
e = q.expect('dbus-method-call', name='RequestConnection',
protocol='fakeprotocol')
conn_object_path = e.conn.object_path
+ fake_conn = e.conn
assert e.parameters == params
e = q.expect('dbus-method-call', name='Connect',
@@ -104,5 +105,13 @@ def test(q, bus, mc):
assert properties.get('RequestedPresence') == requested_presence, \
properties.get('RequestedPresence')
+ new_channel = http_fixed_properties
+ new_channel['org.freedesktop.Telepathy.Channel.TargetHandle'] = 2L
+
+ fake_conn.new_incoming_channel('/foobar', new_channel)
+
+ e = q.expect('dbus-method-call', name='HandleChannels', obj=fake_client,
+ connection=conn_object_path)
+
if __name__ == '__main__':
exec_test(test, {})
--
1.5.6.5
More information about the Telepathy-commits
mailing list