From 65e8bcbaa3fd3a61e188f00316defa27188125dd Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 20 Sep 2013 15:57:19 +0100 Subject: [PATCH 06/10] Add inspect_contact_sync, inspect_contacts_sync and use in simple cases Telepathy 1.0 doesn't have InspectHandles. --- tests/twisted/file-transfer/file_transfer_helper.py | 2 +- tests/twisted/jingle-share/file_transfer_helper.py | 2 +- tests/twisted/jingle-share/test-caps-file-transfer.py | 4 ++-- tests/twisted/jingle-share/test-multift.py | 2 +- tests/twisted/muc/kicked.py | 2 +- tests/twisted/muc/scrollback.py | 3 +-- tests/twisted/muc/test-ensure.py | 4 ++-- tests/twisted/muc/test-muc-invitation.py | 4 ++-- tests/twisted/olpc/olpc-muc-invitation.py | 4 ++-- tests/twisted/olpc/olpc-muc-prop-change.py | 4 ++-- tests/twisted/rostertest.py | 2 +- tests/twisted/servicetest.py | 13 ++++++++++++- tests/twisted/text/test-text-delayed.py | 2 +- tests/twisted/text/test-text-no-body.py | 2 +- tests/twisted/text/test-text.py | 2 +- tests/twisted/tubes/offer-muc-dbus-tube.py | 2 +- tests/twisted/tubes/offer-muc-stream-tube.py | 2 +- 17 files changed, 33 insertions(+), 23 deletions(-) diff --git a/tests/twisted/file-transfer/file_transfer_helper.py b/tests/twisted/file-transfer/file_transfer_helper.py index 3679c37..ae17fe2 100644 --- a/tests/twisted/file-transfer/file_transfer_helper.py +++ b/tests/twisted/file-transfer/file_transfer_helper.py @@ -89,7 +89,7 @@ class FileTransferTest(object): announce_socks5_proxy(self.q, self.stream, disco_event.stanza) self.self_handle = self.conn.Properties.Get(cs.CONN, "SelfHandle") - self.self_handle_name = self.conn.InspectHandles(cs.HT_CONTACT, [self.self_handle])[0] + self.self_handle_name = self.conn.inspect_contact_sync(self.self_handle) def announce_contact(self, name=CONTACT_NAME, metadata=True): self.contact_name = name diff --git a/tests/twisted/jingle-share/file_transfer_helper.py b/tests/twisted/jingle-share/file_transfer_helper.py index 3e8b274..8632ef2 100644 --- a/tests/twisted/jingle-share/file_transfer_helper.py +++ b/tests/twisted/jingle-share/file_transfer_helper.py @@ -78,7 +78,7 @@ class FileTransferTest(object): path=self.conn.object.object_path) self.self_handle = self.conn.Properties.Get(cs.CONN, "SelfHandle") - self.self_handle_name = self.conn.InspectHandles(cs.HT_CONTACT, [self.self_handle])[0] + self.self_handle_name = self.conn.inspect_contact_sync(self.self_handle) def set_target(self, jid): self.target = jid diff --git a/tests/twisted/jingle-share/test-caps-file-transfer.py b/tests/twisted/jingle-share/test-caps-file-transfer.py index 0bf869a..4e6c328 100644 --- a/tests/twisted/jingle-share/test-caps-file-transfer.py +++ b/tests/twisted/jingle-share/test-caps-file-transfer.py @@ -65,9 +65,9 @@ def test2(q, bus, connections, streams): conn1, conn2 = connections stream1, stream2 = streams conn1_handle = conn1.Properties.Get(cs.CONN, 'SelfHandle') - conn1_jid = conn1.InspectHandles(cs.HT_CONTACT, [conn1_handle])[0] + conn1_jid = conn1.inspect_contact_sync(conn1_handle) conn2_handle = conn2.Properties.Get(cs.CONN, 'SelfHandle') - conn2_jid = conn2.InspectHandles(cs.HT_CONTACT, [conn2_handle])[0] + conn2_jid = conn2.inspect_contact_sync(conn2_handle) handle1 = conn2.RequestHandles(cs.HT_CONTACT, [conn1_jid])[0] handle2 = conn1.RequestHandles(cs.HT_CONTACT, [conn2_jid])[0] diff --git a/tests/twisted/jingle-share/test-multift.py b/tests/twisted/jingle-share/test-multift.py index ac9f675..e842767 100644 --- a/tests/twisted/jingle-share/test-multift.py +++ b/tests/twisted/jingle-share/test-multift.py @@ -26,7 +26,7 @@ def test(q, bus, conn, stream): 2L, client) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") - jid = conn.InspectHandles(cs.HT_CONTACT, [self_handle])[0] + jid = conn.inspect_contact_sync(self_handle) iq = IQ(stream, "set") iq['to'] = jid diff --git a/tests/twisted/muc/kicked.py b/tests/twisted/muc/kicked.py index 42c0f5d..6049a63 100644 --- a/tests/twisted/muc/kicked.py +++ b/tests/twisted/muc/kicked.py @@ -17,7 +17,7 @@ def test(q, bus, conn, stream): _, chan, _, _ = join_muc(q, bus, conn, stream, MUC) muc_self_handle = chan.Properties.Get(cs.CHANNEL_IFACE_GROUP, "SelfHandle") - muc_self_jid, = conn.InspectHandles(cs.HT_CONTACT, [muc_self_handle]) + muc_self_jid = conn.inspect_contact_sync(muc_self_handle) # But then Bob kicks us. bob_jid = '%s/bob' % MUC diff --git a/tests/twisted/muc/scrollback.py b/tests/twisted/muc/scrollback.py index 607d3c6..095e502 100644 --- a/tests/twisted/muc/scrollback.py +++ b/tests/twisted/muc/scrollback.py @@ -74,8 +74,7 @@ def test(q, bus, conn, stream): marco = badger(m3) assertEquals([our_jid, bob_jid, marco_jid], - conn.InspectHandles(cs.HT_CONTACT, - [ me, bob, marco ])) + conn.inspect_contacts_sync([ me, bob, marco ])) if __name__ == '__main__': exec_test(test) diff --git a/tests/twisted/muc/test-ensure.py b/tests/twisted/muc/test-ensure.py index e03ae35..f934d14 100644 --- a/tests/twisted/muc/test-ensure.py +++ b/tests/twisted/muc/test-ensure.py @@ -57,7 +57,7 @@ def test_create_ensure(q, conn, bus, stream, room_jid, room_handle): assert local_pending == [], mc.args assert remote_pending == [], mc.args - members = conn.InspectHandles(1, added) + members = conn.inspect_contacts_sync(added) members.sort() assert members == ['%s/bob' % room_jid, '%s/test' % room_jid], members @@ -121,7 +121,7 @@ def test_ensure_ensure(q, conn, bus, stream, room_jid, room_handle): assert local_pending == [], mc.args assert remote_pending == [], mc.args - members = conn.InspectHandles(1, added) + members = conn.inspect_contacts_sync(added) members.sort() assert members == ['%s/bob' % room_jid, '%s/test' % room_jid], members diff --git a/tests/twisted/muc/test-muc-invitation.py b/tests/twisted/muc/test-muc-invitation.py index 797a439..9e406ec 100644 --- a/tests/twisted/muc/test-muc-invitation.py +++ b/tests/twisted/muc/test-muc-invitation.py @@ -38,11 +38,11 @@ def test(q, bus, conn, stream): remote_pending = text_chan.Group.GetRemotePendingMembers() assert len(members) == 1 - assert conn.InspectHandles(1, members)[0] == 'bob@localhost' + assert conn.inspect_contact_sync(members[0]) == 'bob@localhost' bob_handle = members[0] assert len(local_pending) == 1 # FIXME: the username-part-is-nickname assumption - assert conn.InspectHandles(1, local_pending)[0] == \ + assert conn.inspect_contact_sync(local_pending[0]) == \ 'chat@conf.localhost/test' assert len(remote_pending) == 0 diff --git a/tests/twisted/olpc/olpc-muc-invitation.py b/tests/twisted/olpc/olpc-muc-invitation.py index d121bae..c0ceb5c 100644 --- a/tests/twisted/olpc/olpc-muc-invitation.py +++ b/tests/twisted/olpc/olpc-muc-invitation.py @@ -88,10 +88,10 @@ def test(q, bus, conn, stream): remote_pending = group_iface.GetAllMembers()[2] assert len(members) == 1 - assert conn.InspectHandles(1, members)[0] == 'bob@localhost' + assert conn.inspect_contact_sync(members[0]) == 'bob@localhost' assert len(local_pending) == 1 # FIXME: the username-part-is-nickname assumption - assert conn.InspectHandles(1, local_pending)[0] == \ + assert conn.inspect_contact_sync(local_pending[0]) == \ 'chat@conf.localhost/test' assert len(remote_pending) == 0 diff --git a/tests/twisted/olpc/olpc-muc-prop-change.py b/tests/twisted/olpc/olpc-muc-prop-change.py index eb87a57..bad9b15 100644 --- a/tests/twisted/olpc/olpc-muc-prop-change.py +++ b/tests/twisted/olpc/olpc-muc-prop-change.py @@ -70,11 +70,11 @@ def test(q, bus, conn, stream): remote_pending = group_iface.GetAllMembers()[2] assert len(members) == 1 - assert conn.InspectHandles(1, members)[0] == 'bob@localhost' + assert conn.inspect_contact_sync(members[0]) == 'bob@localhost' bob_handle = members[0] assert len(local_pending) == 1 # FIXME: the username-part-is-nickname assumption - assert conn.InspectHandles(1, local_pending)[0] == \ + assert conn.inspect_contact_sync(local_pending[0]) == \ 'chat@conf.localhost/test' assert len(remote_pending) == 0 diff --git a/tests/twisted/rostertest.py b/tests/twisted/rostertest.py index 7e9f121..fcbbc0f 100644 --- a/tests/twisted/rostertest.py +++ b/tests/twisted/rostertest.py @@ -130,7 +130,7 @@ def check_contact_list_signals(q, bus, conn, signals, members = chan.Group.GetMembers() assertEquals(sorted(contacts), - sorted(conn.InspectHandles(cs.HT_CONTACT, members))) + sorted(conn.inspect_contacts_sync(members))) lp_handles = conn.RequestHandles(cs.HT_CONTACT, lp_contacts) rp_handles = conn.RequestHandles(cs.HT_CONTACT, rp_contacts) diff --git a/tests/twisted/servicetest.py b/tests/twisted/servicetest.py index 894d00b..f5f99dc 100644 --- a/tests/twisted/servicetest.py +++ b/tests/twisted/servicetest.py @@ -457,8 +457,19 @@ class ProxyWrapper: return getattr(self.default_interface, name) +class ConnWrapper(ProxyWrapper): + def inspect_contact_sync(self, handle): + return self.inspect_contacts_sync([handle])[0] + + def inspect_contacts_sync(self, handles): + h2asv = self.Contacts.GetContactAttributes(handles, [], True) + ret = [] + for h in handles: + ret.append(h2asv[h][cs.ATTR_CONTACT_ID]) + return ret + def wrap_connection(conn): - return ProxyWrapper(conn, tp_name_prefix + '.Connection', + return ConnWrapper(conn, tp_name_prefix + '.Connection', dict([ (name, tp_name_prefix + '.Connection.Interface.' + name) for name in ['Aliasing', 'Avatars', 'Capabilities', 'Contacts', diff --git a/tests/twisted/text/test-text-delayed.py b/tests/twisted/text/test-text-delayed.py index 3818e06..b08f148 100644 --- a/tests/twisted/text/test-text-delayed.py +++ b/tests/twisted/text/test-text-delayed.py @@ -26,7 +26,7 @@ def test(q, bus, conn, stream): event = q.expect('dbus-signal', signal='NewChannel') assert event.args[1] == cs.CHANNEL_TYPE_TEXT assert event.args[2] == cs.HT_CONTACT - jid = conn.InspectHandles(cs.HT_CONTACT, [event.args[3]])[0] + jid = conn.inspect_contact_sync(event.args[3]) assert jid == 'foo@bar.com' received, message_received = q.expect_many( diff --git a/tests/twisted/text/test-text-no-body.py b/tests/twisted/text/test-text-no-body.py index 2c4095f..62773dc 100644 --- a/tests/twisted/text/test-text-no-body.py +++ b/tests/twisted/text/test-text-no-body.py @@ -29,7 +29,7 @@ def test(q, bus, conn, stream): # first message should be from Bob, not Alice event = q.expect('dbus-signal', signal='NewChannel') assert event.args[1] == cs.CHANNEL_TYPE_TEXT - jid = conn.InspectHandles(cs.HT_CONTACT, [event.args[3]])[0] + jid = conn.inspect_contact_sync(event.args[3]) assert jid == 'bob@foo.com' if __name__ == '__main__': diff --git a/tests/twisted/text/test-text.py b/tests/twisted/text/test-text.py index e7a7ddf..a574d0c 100644 --- a/tests/twisted/text/test-text.py +++ b/tests/twisted/text/test-text.py @@ -31,7 +31,7 @@ def test(q, bus, conn, stream): assert event.args[1] == cs.CHANNEL_TYPE_TEXT assert event.args[2] == cs.HT_CONTACT foo_at_bar_dot_com_handle = event.args[3] - jid = conn.InspectHandles(1, [foo_at_bar_dot_com_handle])[0] + jid = conn.inspect_contact_sync(foo_at_bar_dot_com_handle) assert jid == 'foo@bar.com' assert event.args[4] == False # suppress handler diff --git a/tests/twisted/tubes/offer-muc-dbus-tube.py b/tests/twisted/tubes/offer-muc-dbus-tube.py index fa05c91..9fa66b4 100644 --- a/tests/twisted/tubes/offer-muc-dbus-tube.py +++ b/tests/twisted/tubes/offer-muc-dbus-tube.py @@ -115,7 +115,7 @@ def test(q, bus, conn, stream, access_control): t.check_conn_properties(q, conn) self_handle = conn.Properties.Get(cs.CONN, "SelfHandle") - self_name = conn.InspectHandles(1, [self_handle])[0] + self_name = conn.inspect_contact_sync(self_handle) # offer a D-Bus tube to another room using new API muc = 'chat2@conf.localhost' diff --git a/tests/twisted/tubes/offer-muc-stream-tube.py b/tests/twisted/tubes/offer-muc-stream-tube.py index 2188e82..dfb8768 100644 --- a/tests/twisted/tubes/offer-muc-stream-tube.py +++ b/tests/twisted/tubes/offer-muc-stream-tube.py @@ -136,7 +136,7 @@ def test(q, bus, conn, stream, bytestream_cls, EventPattern('dbus-signal', signal='TubeChannelStateChanged', args=[cs.TUBE_CHANNEL_STATE_OPEN])) tube_self_handle = tube_chan.GetSelfHandle(dbus_interface=cs.CHANNEL_IFACE_GROUP) - assert conn.InspectHandles(cs.HT_CONTACT, [tube_self_handle]) == ['chat@conf.localhost/test'] + assert conn.inspect_contact_sync(tube_self_handle) == 'chat@conf.localhost/test' presence = stream_event.stanza tubes_nodes = xpath.queryForNodes('/presence/tubes[@xmlns="%s"]' -- 1.8.4.rc3