[Telepathy-commits] [telepathy-gabble/master] Move duplicated NewChannels checking to tubetestutil
Will Thompson
will.thompson at collabora.co.uk
Wed Feb 18 08:38:53 PST 2009
---
.../offer-accept-private-dbus-stream-tube-ibb.py | 26 +++---------------
...offer-accept-private-dbus-stream-tube-socks5.py | 28 ++-----------------
tests/twisted/tubes/tubetestutil.py | 21 +++++++++++++++
3 files changed, 29 insertions(+), 46 deletions(-)
diff --git a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
index db3107b..9b8f7ee 100644
--- a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
+++ b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-ibb.py
@@ -33,22 +33,6 @@ new_sample_parameters = dbus.Dictionary({
'i': dbus.Int32(-123),
}, signature='sv')
-def check_NewChannels_signal(new_sig, channel_type, chan_path, contact_handle,
- contact_id, initiator_handle):
- assert len(new_sig) == 1
- assert len(new_sig[0]) == 1 # one channel
- assert len(new_sig[0][0]) == 2 # two struct members
- assert new_sig[0][0][0] == chan_path
- emitted_props = new_sig[0][0][1]
-
- assert emitted_props[CHANNEL_TYPE] == channel_type
- assert emitted_props[TARGET_HANDLE_TYPE] == 1
- assert emitted_props[TARGET_HANDLE] == contact_handle
- assert emitted_props[TARGET_ID] == contact_id
- assert emitted_props[REQUESTED] == True
- assert emitted_props[INITIATOR_HANDLE] == initiator_handle
- assert emitted_props[INITIATOR_ID] == 'test at localhost'
-
def contact_offer_dbus_tube(stream, si_id, tube_id):
iq = IQ(stream, 'set')
iq['to'] = 'test at localhost/Resource'
@@ -189,7 +173,7 @@ def test(q, bus, conn, stream):
chan_path = ret.value[0]
t.check_NewChannel_signal(old_sig.args, CHANNEL_TYPE_TUBES, chan_path, bob_handle, True)
- check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_TUBES, chan_path,
+ t.check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_TUBES, chan_path,
bob_handle, 'bob at localhost', conn.GetSelfHandle())
old_tubes_channel_properties = new_sig.args[0][0]
@@ -236,8 +220,8 @@ def test(q, bus, conn, stream):
t.check_NewChannel_signal(old_sig.args, CHANNEL_TYPE_STREAM_TUBE,
new_chan_path, bob_handle, True)
- check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_STREAM_TUBE, new_chan_path, \
- bob_handle, 'bob at localhost', conn.GetSelfHandle())
+ t.check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_STREAM_TUBE,
+ new_chan_path, bob_handle, 'bob at localhost', conn.GetSelfHandle())
stream_tube_channel_properties = new_sig.args[0][0]
assert TUBE_STATE not in stream_tube_channel_properties
assert TUBE_PARAMETERS not in stream_tube_channel_properties
@@ -290,8 +274,8 @@ def test(q, bus, conn, stream):
# the tube channel (new API) is announced
t.check_NewChannel_signal(new_chan.args, CHANNEL_TYPE_STREAM_TUBE,
None, bob_handle, False)
- check_NewChannels_signal(new_chans.args, CHANNEL_TYPE_STREAM_TUBE, new_chan.args[0],
- bob_handle, "bob at localhost", self_handle)
+ t.check_NewChannels_signal(new_chans.args, CHANNEL_TYPE_STREAM_TUBE,
+ new_chan.args[0], bob_handle, "bob at localhost", self_handle)
props = new_chans.args[0][0][1]
assert TUBE_STATE not in props
diff --git a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
index b517a03..a71078b 100644
--- a/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
+++ b/tests/twisted/tubes/offer-accept-private-dbus-stream-tube-socks5.py
@@ -60,28 +60,6 @@ class S5BFactory(Factory):
def clientConnectionLost(self, connector, reason):
pass
-def check_NewChannels_signal(new_sig, channel_type, chan_path, contact_handle,
- contact_id, initiator_handle):
- assert len(new_sig) == 1
- assert len(new_sig[0]) == 1 # one channel
- assert len(new_sig[0][0]) == 2 # two struct members
- assert new_sig[0][0][0] == chan_path
- emitted_props = new_sig[0][0][1]
-
- assert emitted_props[tp_name_prefix + '.Channel.ChannelType'] ==\
- tp_name_prefix + '.Channel.Type.' + channel_type
- assert emitted_props[tp_name_prefix + '.Channel.TargetHandleType'] == 1
- assert emitted_props[tp_name_prefix + '.Channel.TargetHandle'] ==\
- contact_handle
- assert emitted_props[tp_name_prefix + '.Channel.TargetID'] == \
- contact_id
- assert emitted_props[tp_name_prefix + '.Channel.Requested'] == True
- assert emitted_props[tp_name_prefix + '.Channel.InitiatorHandle'] \
- == initiator_handle
- assert emitted_props[tp_name_prefix + '.Channel.InitiatorID'] == \
- 'test at localhost'
-
-
def test(q, bus, conn, stream):
t.set_up_echo("")
t.set_up_echo("2")
@@ -197,7 +175,7 @@ def test(q, bus, conn, stream):
t.check_NewChannel_signal(old_sig.args, CHANNEL_TYPE_TUBES, chan_path,
bob_handle, True)
- check_NewChannels_signal(new_sig.args, "Tubes", chan_path,
+ t.check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_TUBES, chan_path,
bob_handle, 'bob at localhost', conn.GetSelfHandle())
old_tubes_channel_properties = new_sig.args[0][0]
@@ -231,8 +209,8 @@ def test(q, bus, conn, stream):
t.check_NewChannel_signal(old_sig.args, CHANNEL_TYPE_STREAM_TUBE,
new_chan_path, bob_handle, True)
- check_NewChannels_signal(new_sig.args, "StreamTube.DRAFT", new_chan_path, \
- bob_handle, 'bob at localhost', conn.GetSelfHandle())
+ t.check_NewChannels_signal(new_sig.args, CHANNEL_TYPE_STREAM_TUBE,
+ new_chan_path, bob_handle, 'bob at localhost', conn.GetSelfHandle())
stream_tube_channel_properties = new_sig.args[0][0]
t.check_conn_properties(q, conn,
diff --git a/tests/twisted/tubes/tubetestutil.py b/tests/twisted/tubes/tubetestutil.py
index aa65e67..b5f024d 100644
--- a/tests/twisted/tubes/tubetestutil.py
+++ b/tests/twisted/tubes/tubetestutil.py
@@ -125,6 +125,27 @@ def check_NewChannel_signal(args, channel_type, chan_path, contact_handle,
assert args[3] == contact_handle, (args, contact_handle)
assert args[4] == suppress_handler, (args, suppress_handler)
+def check_NewChannels_signal(args, channel_type, chan_path, contact_handle,
+ contact_id, initiator_handle):
+ """
+ Checks the first argument, a one-tuple of arguments from NewChannels,
+ matches the other arguments.
+ """
+ assert len(args) == 1, args
+ assert len(args[0]) == 1 # one channel
+ path, props = args[0][0]
+
+ assert path == chan_path, (emitted_path, chan_path)
+
+ assert props[CHANNEL_TYPE] == channel_type, (props, channel_type)
+ assert props[TARGET_HANDLE_TYPE] == HT_CONTACT, props
+ assert props[TARGET_HANDLE] == contact_handle, (props, contact_handle)
+ assert props[TARGET_ID] == contact_id, (props, contact_id)
+ assert props[REQUESTED] == True, props
+ assert props[INITIATOR_HANDLE] == initiator_handle, \
+ (props, initiator_handle)
+ assert props[INITIATOR_ID] == 'test at localhost', props
+
def check_channel_properties(q, bus, conn, channel, channel_type,
contact_handle, contact_id, state=None):
"""
--
1.5.6.5
More information about the telepathy-commits
mailing list