def connect_to_salut(self):
        host, port = self._resolve_salut_presence()

        self.outbound = connect_to_stream(self.q, self.contact_name,
            self.self_handle_name, host, port)

        e = self.q.expect('connection-result')
        assert e.succeeded, e.reason
        self.q.expect('stream-opened', connection = self.outbound)
    def connect_to_salut(self):
        host, port = self._resolve_salut_presence()

        self.outbound = connect_to_stream(self.q, self.contact_name,
                                          self.self_handle_name, host, port)

        e = self.q.expect('connection-result')
        assert e.succeeded, e.reason
        self.q.expect('stream-opened', connection=self.outbound)
Beispiel #3
0
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = {"txtvers": "1", "status": "avail"}

    contact_name = "test-text-channel@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name = conn.Properties.Get(cs.CONN, "SelfID")

    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added',
                 name=self_handle_name,
                 protocol=avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    xmpp_connection = connect_to_stream(q, contact_name, self_handle_name,
                                        str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=xmpp_connection)

    # connected to salut, now send a messages as composing part
    # here be sillyness
    parts = OUTGOING_MESSAGE.split(" ")

    for x in xrange(1, len(parts)):
        message = domish.Element(('', 'message'))
        message.addElement('body', content=' '.join(parts[:x]))
        event = message.addElement('x', 'jabber:x:event')
        event.addElement('composing')
        event.addElement('id')
        xmpp_connection.send(message)

    message = domish.Element(('', 'message'))
    message.addElement('body', content=OUTGOING_MESSAGE)
    event = message.addElement('x', 'jabber:x:event')
    event.addElement('composing')
    xmpp_connection.send(message)

    e = q.expect('dbus-signal', signal='Received')
    assert e.args[2] == handle
    assert e.args[5] == OUTGOING_MESSAGE
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = { "txtvers": "1", "status": "avail" }

    contact_name = "test-text-channel@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")

    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()


    e = q.expect('service-resolved', service = service)

    xmpp_connection = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection = xmpp_connection)

    # connected to salut, now send a messages as composing part 
    # here be sillyness
    parts = OUTGOING_MESSAGE.split(" ")

    for x in xrange(1,len(parts)):
        message = domish.Element(('', 'message'))
        message.addElement('body', content=' '.join(parts[:x]))
        event = message.addElement('x', 'jabber:x:event')
        event.addElement('composing')
        event.addElement('id')
        xmpp_connection.send(message)

    message = domish.Element(('', 'message'))
    message.addElement('body', content=OUTGOING_MESSAGE)
    event = message.addElement('x', 'jabber:x:event')
    event.addElement('composing')
    xmpp_connection.send(message)

    e = q.expect('dbus-signal', signal='Received')
    assert e.args[2] == handle
    assert e.args[5] == OUTGOING_MESSAGE
def advertise_caps(q, bus, conn, service, 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.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")
    ret_caps = conn.ContactCapabilities.UpdateCapabilities(
            [(cs.CLIENT + '.Foo', filters, [])])

    presence, event_dbus = q.expect_many(
        EventPattern('service-resolved', service=service),
        EventPattern('dbus-signal', signal='ContactCapabilitiesChanged')
        )
    assertLength(1, event_dbus.args)
    signaled_caps = event_dbus.args[0]

    outbound = connect_to_stream(q, 'test@foobar',
        self_handle_name, str(presence.pt), presence.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=outbound)

    # Expect Salut to reply with the correct caps
    event, namespaces = disco_caps(q, outbound, presence.txt)

    assertSameElements(expected_caps, signaled_caps[self_handle])

    assertContains(ns.TP_FT_METADATA, namespaces)

    for var in expected_features:
        assertContains(var, namespaces)

    for var in unexpected_features:
        assertDoesNotContain(var, namespaces)

    # check the Contacts interface give the same caps
    caps_via_contacts_iface = conn.Contacts.GetContactAttributes(
            [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \
            [self_handle][cs.ATTR_CONTACT_CAPABILITIES]
    assertSameElements(expected_caps, caps_via_contacts_iface)

    # close things...
    outbound.send('</stream:stream>')
    sync_dbus(bus, q, conn)
    outbound.transport.loseConnection()
def advertise_caps(q, bus, conn, service, 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.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name = conn.Properties.Get(cs.CONN, "SelfID")
    ret_caps = conn.ContactCapabilities.UpdateCapabilities([
        (cs.CLIENT + '.Foo', filters, [])
    ])

    presence, event_dbus = q.expect_many(
        EventPattern('service-resolved', service=service),
        EventPattern('dbus-signal', signal='ContactCapabilitiesChanged'))
    assertLength(1, event_dbus.args)
    signaled_caps = event_dbus.args[0]

    outbound = connect_to_stream(q, 'test@foobar', self_handle_name,
                                 str(presence.pt), presence.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=outbound)

    # Expect Salut to reply with the correct caps
    event, namespaces = disco_caps(q, outbound, presence.txt)

    assertSameElements(expected_caps, signaled_caps[self_handle])

    assertContains(ns.TP_FT_METADATA, namespaces)

    for var in expected_features:
        assertContains(var, namespaces)

    for var in unexpected_features:
        assertDoesNotContain(var, namespaces)

    # check the Contacts interface give the same caps
    caps_via_contacts_iface = conn.Contacts.GetContactAttributes(
            [self_handle], [cs.CONN_IFACE_CONTACT_CAPS], False) \
            [self_handle][cs.ATTR_CONTACT_CAPABILITIES]
    assertSameElements(expected_caps, caps_via_contacts_iface)

    # close things...
    outbound.send('</stream:stream>')
    sync_dbus(bus, q, conn)
    outbound.transport.loseConnection()
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = {"txtvers": "1", "status": "avail"}

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name = conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-ichat-incoming-msg@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    # Create a connection to send msg stanza
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added',
                 name=self_handle_name,
                 protocol=avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    outbound = connect_to_stream(q, contact_name, self_handle_name, str(e.pt),
                                 e.port, OutgoingXmppiChatStream)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason
    e = q.expect('stream-opened', connection=outbound)

    msg = domish.Element((None, 'message'))
    msg['to'] = self_handle_name
    msg['type'] = 'chat'
    boddy = msg.addElement('body', content='hi')
    outbound.send(msg)

    e = q.expect('dbus-signal', signal='Received')
    assert e.args[2] == handle
    assert e.args[3] == cs.MT_NORMAL
    assert e.args[5] == "hi"
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = { "txtvers": "1", "status": "avail" }

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-ichat-incoming-msg@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    # Create a connection to send msg stanza
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service = service)

    outbound = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port, OutgoingXmppiChatStream)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason
    e = q.expect('stream-opened', connection = outbound)

    msg = domish.Element((None, 'message'))
    msg['to'] = self_handle_name
    msg['type'] = 'chat'
    boddy = msg.addElement('body', content='hi')
    outbound.send(msg)

    e = q.expect('dbus-signal', signal='Received')
    assert e.args[2] == handle
    assert e.args[3] == cs.MT_NORMAL
    assert e.args[5] == "hi"
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = { "txtvers": "1", "status": "avail" }

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-muc@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    requests_iface = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)

    # Create a connection to send the muc invite
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service = service)

    outbound = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason
    e = q.expect('stream-opened', connection = outbound)

    # connected to Salut, now send the muc invite
    msg = domish.Element((None, 'message'))
    msg['to'] = self_handle_name
    msg['from'] = contact_name
    msg['type'] = 'normal'
    body = msg.addElement('body', content='You got a Clique chatroom invitation')
    invite = msg.addElement((NS_CLIQUE, 'invite'))
    invite.addElement('roomname', content='my-room')
    invite.addElement('reason', content='Inviting to this room')
    # FIXME: we should create a real Clique room and use its IP and port.
    # Hardcode values for now. The IP is a multicast address.
    invite.addElement('address', content='239.255.71.249')
    invite.addElement('port', content='62472')
    outbound.send(msg)

    e = q.expect('dbus-signal', signal='NewChannels',
            predicate=lambda e:
                e.args[0][0][1][cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT)
    channels = e.args[0]
    assert len(channels) == 1
    path, props = channels[0]
    channel = make_channel_proxy(conn, path, "Channel")
    channel_group = make_channel_proxy(conn, path, "Channel.Interface.Group")

    # check channel properties
    # org.freedesktop.Telepathy.Channel D-Bus properties
    assert props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT
    assertContains(cs.CHANNEL_IFACE_GROUP, props[cs.INTERFACES])
    assertContains(cs.CHANNEL_IFACE_MESSAGES, props[cs.INTERFACES])
    assert props[cs.TARGET_ID] == 'my-room'
    assert props[cs.TARGET_HANDLE_TYPE] == HT_ROOM
    assert props[cs.REQUESTED] == False
    assert props[cs.INITIATOR_HANDLE] == handle
    assert props[cs.INITIATOR_ID] == contact_name

    # we are added to local pending
    e = q.expect('dbus-signal', signal='MembersChanged')
    msg, added, removed, lp, rp, actor, reason = e.args
    assert msg == 'Inviting to this room'
    assert added == []
    assert removed == []
    assert lp == [self_handle]
    assert rp == []
    assert actor == handle
    assert reason == 4       # invited

    # TODO: join the muc, check if we are added to remote-pending and then
    # to members. This would need some tweak in Salut and/or the test framework
    # as Clique takes too much time to join the room and so the event times
    # out.

    # TODO: test sending invitations

    # FIXME: fd.o #30531: this ought to work, but doesn't
    #channel_group.RemoveMembersWithReason([self_handle], "bored now", 0)
    channel.Close()
    q.expect('dbus-signal', signal='Closed')
Beispiel #10
0
def setup_incoming_tests(q, bus, conn):
    handle, contact_name, listener = setup_tests(q, bus, conn)

    self_handle = conn.GetSelfHandle()
    self_handle_name = conn.InspectHandles(cs.HT_CONTACT, [self_handle])[0]

    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added',
                 name=self_handle_name,
                 protocol=avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    outbound = connect_to_stream(q, contact_name, self_handle_name, str(e.pt),
                                 e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=outbound)

    iq = IQ(None, 'get')
    iq['id'] = 'le-loldongs'
    iq['from'] = contact_name
    iq['to'] = self_handle_name
    msg = iq.addElement((ycs.MESSAGE_NS, 'message'))
    msg['from-service'] = 'the.from.service'
    msg['to-service'] = 'the.to.service'
    msg['owl-companions'] = 'the pussy cat'
    msg['destination'] = 'sea'
    msg['seacraft'] = 'beautiful pea green boat'

    lol = msg.addElement((None, 'lol'))
    lol['some'] = 'stuff'
    lol['to'] = 'fill'
    lol['the'] = 'time'
    lol.addElement((None, 'look-into-my-eyes'),
                   content='and tell me how boring writing these tests is')

    outbound.send(iq)

    e = q.expect('dbus-signal',
                 signal='NewChannels',
                 predicate=lambda e: e.args[0][0][1][cs.CHANNEL_TYPE] == ycs.
                 CHANNEL_IFACE)
    path, props = e.args[0][0]

    assertEquals(handle, props[cs.INITIATOR_HANDLE])
    assertEquals(contact_name, props[cs.INITIATOR_ID])
    assertEquals(False, props[cs.REQUESTED])
    assertEquals(handle, props[cs.TARGET_HANDLE])
    assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE])
    assertEquals(contact_name, props[cs.TARGET_ID])

    assertEquals('the.from.service', props[ycs.INITIATOR_SERVICE])
    assertEquals('the.to.service', props[ycs.TARGET_SERVICE])
    assertEquals(ycs.REQUEST_TYPE_GET, props[ycs.REQUEST_TYPE])
    assertEquals(
        {
            'destination': 'sea',
            'owl-companions': 'the pussy cat',
            'seacraft': 'beautiful pea green boat'
        }, props[ycs.REQUEST_ATTRIBUTES])

    assertEquals('<?xml version="1.0" encoding="UTF-8"?>\n' \
                     '<message seacraft="beautiful pea green boat" ' \
                     'from-service="the.from.service" destination="sea" ' \
                     'owl-companions="the pussy cat" to-service="the.to.service" ' \
                     'xmlns="urn:ytstenut:message">' \
                     '<lol to="fill" the="time" some="stuff">' \
                     '<look-into-my-eyes>and tell me how boring ' \
                     'writing these tests is</look-into-my-eyes>' \
                     '</lol></message>\n', props[ycs.REQUEST_BODY])

    # finally we have our channel
    chan = wrap_channel(bus, conn, path)

    # let's check we can't call Request()
    call_async(q, chan, 'Request')
    q.expect('dbus-error', method='Request')

    return chan, outbound, contact_name, self_handle_name
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = { "txtvers": "1", "status": "avail" }

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-text-channel@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    # create a clique room
    basic_txt = { "txtvers": "0"}
    AvahiAnnouncer("myroom", "_clique._udp", 41377, basic_txt)

    # connect a stream
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service = service)

    xmpp_connection = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection = xmpp_connection)

    # send an invitation
    message = domish.Element(('', 'message'))
    message['type'] = 'normal'
    message.addElement('body', content='You got a Clique chatroom invitation')
    invite = message.addElement((NS_CLIQUE, 'invite'))
    invite.addElement('roomname', content='myroom')
    invite.addElement('reason', content='Inviting to this room')
    invite.addElement('address', content='127.0.0.1')
    invite.addElement('port', content='41377')
    xmpp_connection.send(message)

    # group channel is created
    e = q.expect('dbus-signal', signal='NewChannel',
            predicate=lambda e:
                e.args[1] == cs.CHANNEL_TYPE_TEXT and
                e.args[2] == cs.HT_ROOM)
    path = e.args[0]
    channel = make_channel_proxy(conn, path, 'Channel')
    props_iface = dbus.Interface(bus.get_object(conn.object.bus_name, path),
        dbus.PROPERTIES_IFACE)

    q.expect('dbus-signal', signal='MembersChanged', path=path)

    lp_members = props_iface.Get('org.freedesktop.Telepathy.Channel.Interface.Group',
        'LocalPendingMembers')

    assert len(lp_members) == 1
    added, actor, reason, msg = lp_members[0]

    assert added == self_handle
    assert actor == handle
    assert reason == 4                       #invited
    assert msg == 'Inviting to this room'

    # decline invitation
    channel.Close()
    q.expect('dbus-signal', signal='Closed')
def test(q, bus, conn):
    contact_name = "test-hct@" + get_host_name()

    call_async(q, conn.Future, 'EnsureSidecar', ycs.STATUS_IFACE)
    conn.Connect()

    q.expect('dbus-signal', signal='StatusChanged', args=[0, 0])

    e = q.expect('dbus-return', method='EnsureSidecar')
    path, props = e.value
    assertEquals({}, props)

    status = ProxyWrapper(bus.get_object(conn.bus_name, path),
                          ycs.STATUS_IFACE, {})

    discovered = status.Get(ycs.STATUS_IFACE, 'DiscoveredServices',
                            dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals({}, discovered)

    self_handle = conn.GetSelfHandle()
    self_handle_name =  conn.InspectHandles(cs.HT_CONTACT, [self_handle])[0]

    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()

    q.expect('service-resolved', service=service)

    # now update the caps
    conn.ContactCapabilities.UpdateCapabilities([
        ('well.gnome.name', [],
         ['org.freedesktop.ytstenut.xpmn.Channel/uid/org.gnome.Banshee',
          'org.freedesktop.ytstenut.xpmn.Channel/type/application',
          'org.freedesktop.ytstenut.xpmn.Channel/name/en_GB/Banshee Media Player',
          'org.freedesktop.ytstenut.xpmn.Channel/name/fr/Banshee Lecteur de Musique',
          'org.freedesktop.ytstenut.xpmn.Channel/caps/urn:ytstenut:capabilities:yts-caps-audio',
          'org.freedesktop.ytstenut.xpmn.Channel/caps/urn:ytstenut:data:jingle:rtp'])])

    e, _ = q.expect_many(EventPattern('service-resolved', service=service),
                         EventPattern('dbus-signal', signal='ServiceAdded'))
    node = txt_get_key(e.txt, 'node')
    ver = txt_get_key(e.txt, 'ver')

    # don't check the hash here because it could change in salut and
    # it would break this test even though it wouldn't /actually/ be
    # broken

    outbound = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)
    e = q.expect('connection-result')
    assert e.succeeded, e.reason
    e = q.expect('stream-opened', connection=outbound)

    # ask what this ver means
    request = \
        elem_iq(outbound, 'get', from_=contact_name)(
          elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
        )
    outbound.send(request)

    # receive caps
    e = q.expect('stream-iq', connection=outbound,
                 query_ns=ns.DISCO_INFO, iq_id=request['id'])

    iq = e.stanza
    query = iq.children[0]

    x = None
    for child in query.children:
        if child.name == 'x' and child.uri == ns.X_DATA:
            # we should only have one child
            assert x is None
            x = child
            # don't break here as we can waste time to make sure x
            # isn't assigned twice

    assert x is not None

    for field in x.children:
        if field['var'] == 'FORM_TYPE':
            assertEquals('hidden', field['type'])
            assertEquals('urn:ytstenut:capabilities#org.gnome.Banshee',
                         field.children[0].children[0])
        elif field['var'] == 'type':
            assertEquals('application', field.children[0].children[0])
        elif field['var'] == 'name':
            names = [a.children[0] for a in field.children]
            assertLength(2, names)
            assertContains('en_GB/Banshee Media Player', names)
            assertContains('fr/Banshee Lecteur de Musique', names)
        elif field['var'] == 'capabilities':
            caps = [a.children[0] for a in field.children]
            assertLength(2, caps)
            assertContains('urn:ytstenut:capabilities:yts-caps-audio', caps)
            assertContains('urn:ytstenut:data:jingle:rtp', caps)
        else:
            assert False

    # now add another service
    forbidden = [EventPattern('dbus-signal', signal='ServiceRemoved')]
    q.forbid_events(forbidden)

    conn.ContactCapabilities.UpdateCapabilities([
        ('another.nice.gname', [],
         ['org.freedesktop.ytstenut.xpmn.Channel/uid/org.gnome.Eog',
          'org.freedesktop.ytstenut.xpmn.Channel/type/application',
          'org.freedesktop.ytstenut.xpmn.Channel/name/en_GB/Eye Of Gnome',
          'org.freedesktop.ytstenut.xpmn.Channel/name/it/Occhio Di uno Gnomo',
          'org.freedesktop.ytstenut.xpmn.Channel/caps/urn:ytstenut:capabilities:yts-picz'])])

    e = q.expect('dbus-signal', signal='ServiceAdded')

    sync_dbus(bus, q, conn)

    discovered = status.Get(ycs.STATUS_IFACE, 'DiscoveredServices',
                            dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals({'testsuite@testsuite':
                      {'org.gnome.Banshee': ('application',
                                             {'en_GB': 'Banshee Media Player',
                                              'fr': 'Banshee Lecteur de Musique'},
                                             ['urn:ytstenut:capabilities:yts-caps-audio',
                                              'urn:ytstenut:data:jingle:rtp']),
                       'org.gnome.Eog': ('application',
                                         {'en_GB': 'Eye Of Gnome',
                                          'it': 'Occhio Di uno Gnomo'},
                                         ['urn:ytstenut:capabilities:yts-picz'])}},
                 discovered)

    q.unforbid_events(forbidden)

    forbidden = [EventPattern('dbus-signal', signal='ServiceRemoved',
                              args=[self_handle_name, 'org.gnome.Eog'])]
    q.forbid_events(forbidden)

    conn.ContactCapabilities.UpdateCapabilities([
            ('well.gnome.name', [], [])])

    e = q.expect('dbus-signal', signal='ServiceRemoved',
                 args=[self_handle_name, 'org.gnome.Banshee'])

    sync_dbus(bus, q, conn)

    discovered = status.Get(ycs.STATUS_IFACE, 'DiscoveredServices',
                            dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals({'testsuite@testsuite':
                      {'org.gnome.Eog': ('application',
                                         {'en_GB': 'Eye Of Gnome',
                                          'it': 'Occhio Di uno Gnomo'},
                                         ['urn:ytstenut:capabilities:yts-picz'])}},
                 discovered)

    q.unforbid_events(forbidden)

    conn.ContactCapabilities.UpdateCapabilities([
            ('another.nice.gname', [], [])])

    e = q.expect('dbus-signal', signal='ServiceRemoved',
                 args=[self_handle_name, 'org.gnome.Eog'])

    discovered = status.Get(ycs.STATUS_IFACE, 'DiscoveredServices',
                            dbus_interface=dbus.PROPERTIES_IFACE)
    assertEquals({}, discovered)
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = {"txtvers": "1", "status": "avail"}

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name = conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-muc@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    requests_iface = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)

    # Create a connection to send the muc invite
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added',
                 name=self_handle_name,
                 protocol=avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    outbound = connect_to_stream(q, contact_name, self_handle_name, str(e.pt),
                                 e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason
    e = q.expect('stream-opened', connection=outbound)

    # connected to Salut, now send the muc invite
    msg = domish.Element((None, 'message'))
    msg['to'] = self_handle_name
    msg['from'] = contact_name
    msg['type'] = 'normal'
    body = msg.addElement('body',
                          content='You got a Clique chatroom invitation')
    invite = msg.addElement((NS_CLIQUE, 'invite'))
    invite.addElement('roomname', content='my-room')
    invite.addElement('reason', content='Inviting to this room')
    # FIXME: we should create a real Clique room and use its IP and port.
    # Hardcode values for now. The IP is a multicast address.
    invite.addElement('address', content='239.255.71.249')
    invite.addElement('port', content='62472')
    outbound.send(msg)

    e = q.expect('dbus-signal',
                 signal='NewChannels',
                 predicate=lambda e: e.args[0][0][1][cs.CHANNEL_TYPE] == cs.
                 CHANNEL_TYPE_TEXT)
    channels = e.args[0]
    assert len(channels) == 1
    path, props = channels[0]
    channel = make_channel_proxy(conn, path, "Channel")
    channel_group = make_channel_proxy(conn, path, "Channel.Interface.Group")

    # check channel properties
    # org.freedesktop.Telepathy.Channel D-Bus properties
    assert props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT
    assertContains(cs.CHANNEL_IFACE_GROUP, props[cs.INTERFACES])
    assertContains(cs.CHANNEL_IFACE_MESSAGES, props[cs.INTERFACES])
    assert props[cs.TARGET_ID] == 'my-room'
    assert props[cs.TARGET_HANDLE_TYPE] == HT_ROOM
    assert props[cs.REQUESTED] == False
    assert props[cs.INITIATOR_HANDLE] == handle
    assert props[cs.INITIATOR_ID] == contact_name

    # we are added to local pending
    e = q.expect('dbus-signal', signal='MembersChanged')
    msg, added, removed, lp, rp, actor, reason = e.args
    assert msg == 'Inviting to this room'
    assert added == []
    assert removed == []
    assert lp == [self_handle]
    assert rp == []
    assert actor == handle
    assert reason == 4  # invited

    # TODO: join the muc, check if we are added to remote-pending and then
    # to members. This would need some tweak in Salut and/or the test framework
    # as Clique takes too much time to join the room and so the event times
    # out.

    # TODO: test sending invitations

    # FIXME: fd.o #30531: this ought to work, but doesn't
    #channel_group.RemoveMembersWithReason([self_handle], "bored now", 0)
    channel.Close()
    q.expect('dbus-signal', signal='Closed')
Beispiel #14
0
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = {"txtvers": "1", "status": "avail"}

    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name = conn.Properties.Get(cs.CONN, "SelfID")

    contact_name = "test-text-channel@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    # create a clique room
    basic_txt = {"txtvers": "0"}
    AvahiAnnouncer("myroom", "_clique._udp", 41377, basic_txt)

    # connect a stream
    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added',
                 name=self_handle_name,
                 protocol=avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    xmpp_connection = connect_to_stream(q, contact_name, self_handle_name,
                                        str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=xmpp_connection)

    # send an invitation
    message = domish.Element(('', 'message'))
    message['type'] = 'normal'
    message.addElement('body', content='You got a Clique chatroom invitation')
    invite = message.addElement((NS_CLIQUE, 'invite'))
    invite.addElement('roomname', content='myroom')
    invite.addElement('reason', content='Inviting to this room')
    invite.addElement('address', content='127.0.0.1')
    invite.addElement('port', content='41377')
    xmpp_connection.send(message)

    # group channel is created
    e = q.expect('dbus-signal',
                 signal='NewChannel',
                 predicate=lambda e: e.args[1] == cs.CHANNEL_TYPE_TEXT and e.
                 args[2] == cs.HT_ROOM)
    path = e.args[0]
    channel = make_channel_proxy(conn, path, 'Channel')
    props_iface = dbus.Interface(bus.get_object(conn.object.bus_name, path),
                                 dbus.PROPERTIES_IFACE)

    q.expect('dbus-signal', signal='MembersChanged', path=path)

    lp_members = props_iface.Get(
        'org.freedesktop.Telepathy.Channel.Interface.Group',
        'LocalPendingMembers')

    assert len(lp_members) == 1
    added, actor, reason, msg = lp_members[0]

    assert added == self_handle
    assert actor == handle
    assert reason == 4  #invited
    assert msg == 'Inviting to this room'

    # decline invitation
    channel.Close()
    q.expect('dbus-signal', signal='Closed')
def test(q, bus, conn):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0L, 0L])
    basic_txt = { "txtvers": "1", "status": "avail" }

    contact_name = "test-text-channel@" + get_host_name()
    listener, port = setup_stream_listener(q, contact_name)

    announcer = AvahiAnnouncer(contact_name, "_presence._tcp", port, basic_txt)

    handle = wait_for_contact_in_publish(q, bus, conn, contact_name)

    t = conn.Requests.CreateChannel({
        cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT,
        cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
        cs.TARGET_HANDLE: handle})[0]
    text_channel = make_channel_proxy(conn, t, "Channel.Type.Text")
    text_channel.Send(cs.MT_NORMAL, INCOMING_MESSAGE)

    e = q.expect('incoming-connection', listener = listener)
    incoming = e.connection

    e = q.expect('stream-message', connection = incoming)
    assert e.message_type == "chat"
    body = xpath.queryForNodes("/message/body",  e.stanza )
    assert map(str, body) == [ INCOMING_MESSAGE ]

    # drop the connection
    incoming.transport.loseConnection()

    # Now send a message to salut
    self_handle = conn.Properties.Get(cs.CONN, "SelfHandle")
    self_handle_name =  conn.Properties.Get(cs.CONN, "SelfID")


    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name = self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()


    e = q.expect('service-resolved', service = service)

    outbound = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection = outbound)

    # connected to salut, now send a message
    message = domish.Element(('', 'message'))
    message['type'] = "chat"
    message.addElement('body', content=OUTGOING_MESSAGE)

    e.connection.send(message)

    e = q.expect('dbus-signal', signal='Received')
    assert e.args[2] == handle
    assert e.args[3] == cs.MT_NORMAL
    assert e.args[5] == OUTGOING_MESSAGE
def setup_incoming_tests(q, bus, conn):
    handle, contact_name, listener = setup_tests(q, bus, conn)

    self_handle = conn.GetSelfHandle()
    self_handle_name =  conn.InspectHandles(cs.HT_CONTACT, [self_handle])[0]

    AvahiListener(q).listen_for_service("_presence._tcp")
    e = q.expect('service-added', name=self_handle_name,
        protocol = avahi.PROTO_INET)
    service = e.service
    service.resolve()

    e = q.expect('service-resolved', service=service)

    outbound = connect_to_stream(q, contact_name,
        self_handle_name, str(e.pt), e.port)

    e = q.expect('connection-result')
    assert e.succeeded, e.reason

    e = q.expect('stream-opened', connection=outbound)

    iq = IQ(None, 'get')
    iq['id'] = 'le-loldongs'
    iq['from'] = contact_name
    iq['to'] = self_handle_name
    msg = iq.addElement((ycs.MESSAGE_NS, 'message'))
    msg['from-service'] = 'the.from.service'
    msg['to-service'] = 'the.to.service'
    msg['owl-companions'] = 'the pussy cat'
    msg['destination'] = 'sea'
    msg['seacraft'] = 'beautiful pea green boat'

    lol = msg.addElement((None, 'lol'))
    lol['some'] = 'stuff'
    lol['to'] = 'fill'
    lol['the'] = 'time'
    lol.addElement((None, 'look-into-my-eyes'),
                   content='and tell me how boring writing these tests is')

    outbound.send(iq)

    e = q.expect('dbus-signal', signal='NewChannels', predicate=lambda e:
                     e.args[0][0][1][cs.CHANNEL_TYPE] == ycs.CHANNEL_IFACE)
    path, props = e.args[0][0]

    assertEquals(handle, props[cs.INITIATOR_HANDLE])
    assertEquals(contact_name, props[cs.INITIATOR_ID])
    assertEquals(False, props[cs.REQUESTED])
    assertEquals(handle, props[cs.TARGET_HANDLE])
    assertEquals(cs.HT_CONTACT, props[cs.TARGET_HANDLE_TYPE])
    assertEquals(contact_name, props[cs.TARGET_ID])

    assertEquals('the.from.service', props[ycs.INITIATOR_SERVICE])
    assertEquals('the.to.service', props[ycs.TARGET_SERVICE])
    assertEquals(ycs.REQUEST_TYPE_GET, props[ycs.REQUEST_TYPE])
    assertEquals({'destination': 'sea',
                  'owl-companions': 'the pussy cat',
                  'seacraft': 'beautiful pea green boat'},
                 props[ycs.REQUEST_ATTRIBUTES])

    assertEquals('<?xml version="1.0" encoding="UTF-8"?>\n' \
                     '<message seacraft="beautiful pea green boat" ' \
                     'from-service="the.from.service" destination="sea" ' \
                     'owl-companions="the pussy cat" to-service="the.to.service" ' \
                     'xmlns="urn:ytstenut:message">' \
                     '<lol to="fill" the="time" some="stuff">' \
                     '<look-into-my-eyes>and tell me how boring ' \
                     'writing these tests is</look-into-my-eyes>' \
                     '</lol></message>\n', props[ycs.REQUEST_BODY])

    # finally we have our channel
    chan = wrap_channel(bus, conn, path)

    # let's check we can't call Request()
    call_async(q, chan, 'Request')
    q.expect('dbus-error', method='Request')

    return chan, outbound, contact_name, self_handle_name