diff --git a/tests/twisted/caps/tube-caps.py b/tests/twisted/caps/tube-caps.py index 3d3f698..004f2f4 100644 --- a/tests/twisted/caps/tube-caps.py +++ b/tests/twisted/caps/tube-caps.py @@ -40,14 +40,14 @@ import dbus from twisted.words.xish import xpath from servicetest import assertEquals, assertLength, assertContains,\ - assertDoesNotContain + assertDoesNotContain, sync_dbus from gabbletest import exec_test, make_result_iq, sync_stream, make_presence import constants as cs from caps_helper import compute_caps_hash, text_fixed_properties,\ text_allowed_properties, stream_tube_fixed_properties, stream_tube_allowed_properties,\ dbus_tube_fixed_properties, dbus_tube_allowed_properties, receive_presence_and_ask_caps,\ - caps_contain, ft_fixed_properties, ft_allowed_properties + caps_contain import ns specialized_tube_allowed_properties = dbus.Array([cs.TARGET_HANDLE, @@ -125,17 +125,17 @@ def receive_caps(q, conn, stream, contact, contact_handle, features, if expect_ccc: event = q.expect('dbus-signal', signal='ContactCapabilitiesChanged') announced_ccs, = event.args - assertSameElements(expected_caps, announced_ccs) + assertSameElements(expected_caps, announced_ccs[contact_handle]) else: # Make sure Gabble's got the caps sync_stream(q, stream) caps = conn.ContactCapabilities.GetContactCapabilities([contact_handle]) - assertSameElements(expected_caps, caps) + assertSameElements(expected_caps, caps[contact_handle]) # test again, to check GetContactCapabilities does not have side effect caps = conn.ContactCapabilities.GetContactCapabilities([contact_handle]) - assertSameElements(expected_caps, caps) + assertSameElements(expected_caps, caps[contact_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( @@ -150,12 +150,11 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact): # contact yet. caps = conn.ContactCapabilities.GetContactCapabilities([contact_handle]) - basic_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties)]}) + basic_caps = [(text_fixed_properties, text_allowed_properties)] # Since we don't know their caps, they should be omitted from the dict, # rather than present with no caps, but all contacts have text chat caps. - assertEquals(basic_caps, caps) + assertEquals(basic_caps, caps[contact_handle]) # send presence with no tube cap # We don't expect ContactCapabilitiesChanged to be emitted here: we always @@ -164,52 +163,41 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact): expect_ccc=False) # send presence with generic tubes caps - generic_tubes_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties)]}) + generic_tubes_caps = basic_caps + [ + (stream_tube_fixed_properties, stream_tube_allowed_properties), + (dbus_tube_fixed_properties, dbus_tube_allowed_properties) + ] receive_caps(q, conn, stream, contact, contact_handle, [ns.TUBES], generic_tubes_caps) # send presence with 1 stream tube cap - daap_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties)]}) + daap_caps = generic_tubes_caps + [ + (bidir_daap_fixed_properties, specialized_tube_allowed_properties) + ] receive_caps(q, conn, stream, contact, contact_handle, [ns.TUBES + '/stream#daap'], daap_caps) # send presence with 1 D-Bus tube cap - xiangqi_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (xiangqi_fixed_properties, specialized_tube_allowed_properties)]}) + xiangqi_caps = generic_tubes_caps + [ + (xiangqi_fixed_properties, specialized_tube_allowed_properties) + ] receive_caps(q, conn, stream, contact, contact_handle, [ns.TUBES + '/dbus#com.example.Xiangqi'], xiangqi_caps) # send presence with both D-Bus and stream tube caps - daap_xiangqi_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties), - (xiangqi_fixed_properties, specialized_tube_allowed_properties)]}) + daap_xiangqi_caps = xiangqi_caps + [ + (bidir_daap_fixed_properties, specialized_tube_allowed_properties), + ] receive_caps(q, conn, stream, contact, contact_handle, [ns.TUBES + '/dbus#com.example.Xiangqi', ns.TUBES + '/stream#daap', ], daap_xiangqi_caps) # send presence with 4 tube caps - all_tubes_caps = dbus.Dictionary({contact_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties), + all_tubes_caps = daap_xiangqi_caps + [ (http_fixed_properties, specialized_tube_allowed_properties), - (xiangqi_fixed_properties, specialized_tube_allowed_properties), - (go_fixed_properties, specialized_tube_allowed_properties)]}) + (go_fixed_properties, specialized_tube_allowed_properties) + ] receive_caps(q, conn, stream, contact, contact_handle, [ns.TUBES + '/dbus#com.example.Xiangqi', ns.TUBES + '/dbus#com.example.Go', @@ -225,8 +213,11 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact): ], daap_xiangqi_caps, expect_disco=False) -def advertise_caps(q, conn, stream, filters, expected_features, unexpected_features, +def advertise_caps(q, bus, conn, stream, filters, expected_features, unexpected_features, expected_caps): + # make sure nothing from a previous update is still running + sync_dbus(bus, q, conn) + self_handle = conn.GetSelfHandle() ret_caps = conn.ContactCapabilities.UpdateCapabilities( [(cs.CLIENT + '.Foo', filters, [])]) @@ -234,7 +225,7 @@ def advertise_caps(q, conn, stream, filters, expected_features, unexpected_featu # Expect Gabble to reply with the correct caps event, namespaces, _, signaled_caps = receive_presence_and_ask_caps(q, stream) - assertSameElements(expected_caps, signaled_caps) + assertSameElements(expected_caps, signaled_caps[self_handle]) assertContains(ns.TUBES, namespaces) @@ -246,7 +237,7 @@ def advertise_caps(q, conn, stream, filters, expected_features, unexpected_featu # Check our own caps caps = conn.ContactCapabilities.GetContactCapabilities([self_handle]) - assertSameElements(expected_caps, caps) + assertSameElements(expected_caps, caps[self_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( @@ -257,43 +248,28 @@ def advertise_caps(q, conn, stream, filters, expected_features, unexpected_featu def test_tube_caps_to_contact(q, bus, conn, stream): self_handle = conn.GetSelfHandle() - basic_caps = dbus.Dictionary({self_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - ]}) - daap_caps = dbus.Dictionary({self_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties), - (ft_fixed_properties, ft_allowed_properties)]}) - xiangqi_caps = dbus.Dictionary({self_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (xiangqi_fixed_properties, specialized_tube_allowed_properties), - (ft_fixed_properties, ft_allowed_properties)]}) - daap_xiangqi_caps = dbus.Dictionary({self_handle: - [(text_fixed_properties, text_allowed_properties), + basic_caps = [ + (text_fixed_properties, text_allowed_properties), (stream_tube_fixed_properties, stream_tube_allowed_properties), (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties), + ] + daap_caps = basic_caps + [ + (bidir_daap_fixed_properties, specialized_tube_allowed_properties), + ] + xiangqi_caps = basic_caps + [ (xiangqi_fixed_properties, specialized_tube_allowed_properties), - (ft_fixed_properties, ft_allowed_properties)]}) - all_tubes_caps = dbus.Dictionary({self_handle: - [(text_fixed_properties, text_allowed_properties), - (stream_tube_fixed_properties, stream_tube_allowed_properties), - (dbus_tube_fixed_properties, dbus_tube_allowed_properties), - (incoming_daap_fixed_properties, specialized_tube_allowed_properties), + ] + daap_xiangqi_caps = xiangqi_caps + [ + (bidir_daap_fixed_properties, specialized_tube_allowed_properties) + ] + all_tubes_caps = daap_xiangqi_caps + [ (http_fixed_properties, specialized_tube_allowed_properties), - (xiangqi_fixed_properties, specialized_tube_allowed_properties), - (go_fixed_properties, specialized_tube_allowed_properties), - (ft_fixed_properties, ft_allowed_properties)]}) + (go_fixed_properties, specialized_tube_allowed_properties) + ] # Check our own caps caps = conn.ContactCapabilities.GetContactCapabilities([self_handle]) - assertEquals(basic_caps, caps) + assertEquals(basic_caps, caps[self_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( @@ -308,7 +284,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): # Check our own caps caps = conn.ContactCapabilities.GetContactCapabilities([self_handle]) assertLength(1, caps) - assertEquals(basic_caps, caps) + assertEquals(basic_caps, caps[self_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( @@ -316,7 +292,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertEquals(caps[self_handle], caps_via_contacts_iface) - sync_stream(q, stream) + sync_dbus(bus, q, conn) # Advertise a Requested=True tube cap conn.ContactCapabilities.UpdateCapabilities( @@ -325,7 +301,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): # Check our own caps caps = conn.ContactCapabilities.GetContactCapabilities([self_handle]) assertLength(1, caps) - assertEquals(basic_caps, caps) + assertEquals(basic_caps, caps[self_handle]) # check the Contacts interface give the same caps caps_via_contacts_iface = conn.Contacts.GetContactAttributes( @@ -333,9 +309,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): [self_handle][cs.ATTR_CONTACT_CAPABILITIES] assertEquals(caps[self_handle], caps_via_contacts_iface) - sync_stream(q, stream) - - advertise_caps(q, conn, stream, + advertise_caps(q, bus, conn, stream, [bidir_daap_fixed_properties], [ns.TUBES + '/stream#daap'], [ns.TUBES + '/stream#http', @@ -344,7 +318,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): ], daap_caps) - advertise_caps(q, conn, stream, + advertise_caps(q, bus, conn, stream, [outgoing_daap_fixed_properties, xiangqi_fixed_properties], [ns.TUBES + '/dbus#com.example.Xiangqi'], [ns.TUBES + '/stream#daap', @@ -353,7 +327,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): ], xiangqi_caps) - advertise_caps(q, conn, stream, + advertise_caps(q, bus, conn, stream, [incoming_daap_fixed_properties, outgoing_daap_fixed_properties, xiangqi_fixed_properties], [ns.TUBES + '/dbus#com.example.Xiangqi', @@ -364,7 +338,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): ], daap_xiangqi_caps) - advertise_caps(q, conn, stream, + advertise_caps(q, bus, conn, stream, [incoming_daap_fixed_properties, http_fixed_properties, go_fixed_properties, xiangqi_fixed_properties], [ns.TUBES + '/dbus#com.example.Xiangqi', @@ -376,7 +350,7 @@ def test_tube_caps_to_contact(q, bus, conn, stream): all_tubes_caps) # test daap + xiangqi again for some reason - advertise_caps(q, conn, stream, + advertise_caps(q, bus, conn, stream, [incoming_daap_fixed_properties, xiangqi_fixed_properties], [ns.TUBES + '/dbus#com.example.Xiangqi', ns.TUBES + '/stream#daap',