diff options
author | Jonathon Jongsma <jonathon.jongsma@collabora.co.uk> | 2009-01-29 10:41:31 -0600 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2012-04-08 09:42:40 +0100 |
commit | 2e852a3bb80afc785174734cf1c877ffc918df88 (patch) | |
tree | 220233dcf948a9e777dad69af4626134515c0390 /tests | |
parent | e0453c6ea47e1ee1ffe76acf2f0f6e9a94487fcb (diff) |
Initial support for listing IRC channels
Added IdleRoomlistManager and IdleRoomlistChannel classes. There is a basic
test included as well. Things seem to work ok (e.g. I can display a list of
channels in empathy), but it hasn't been extensively tested and I have made some
possibly questionable design decisions (e.g. only creating a single
RoomlistChannel rather than creating a new one every time one is requested). I
don't fully understand the implication of that choice yet, so I need to do some
more work to figure out whether that needs to be changed.
There seems to be a crash when closing down the channel that also needs to be
investigated.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/Makefile.am | 1 | ||||
-rw-r--r-- | tests/twisted/channels/room-list-channel.py | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 64cb611..e6b0005 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -15,6 +15,7 @@ TWISTED_TESTS = \ channels/requests-create.py \ channels/requests-muc.py \ channels/muc-channel-topic.py \ + channels/room-list-channel.py \ messages/accept-invalid-nicks.py \ messages/contactinfo-request.py \ messages/messages-iface.py \ diff --git a/tests/twisted/channels/room-list-channel.py b/tests/twisted/channels/room-list-channel.py new file mode 100644 index 0000000..e2c0387 --- /dev/null +++ b/tests/twisted/channels/room-list-channel.py @@ -0,0 +1,77 @@ + +""" +Test getting a room-list channel +""" + +from idletest import exec_test, BaseIRCServer +from servicetest import EventPattern, call_async, tp_name_prefix, tp_path_prefix +import dbus + +HANDLE_TYPE_NONE=0 + +TEST_CHANNELS = ( + ('#foo', 4, 'discussion about foo'), + ('#bar', 8, 'discussion about bar'), + ('#baz', 230, '') #empty topic + ) + +def check_rooms(received_rooms): + for room in received_rooms: + assert room[1] == tp_name_prefix + '.Channel.Type.Text' + info = room[2] + found = False + for r in TEST_CHANNELS: + if r[0] == info['name']: + found = True + assert r[1] == info['members'] and r[2] == info['subject'] + break; + assert found + return True + + +class RoomListServer(BaseIRCServer): + def handleLIST(self, args, prefix): + for chan in TEST_CHANNELS: + self.sendMessage('322', '%s %s %d :%s' % (self.nick, chan[0], chan[1], chan[2]), + prefix="idle.test.server") + self.sendMessage('323', '%s :End of /LIST' % self.nick, prefix="idle.test.server") + pass + +def test(q, bus, conn, stream): + conn.Connect() + q.expect_many( + EventPattern('dbus-signal', signal='StatusChanged', args=[1, 1]), + EventPattern('irc-connected')) + q.expect('dbus-signal', signal='SelfHandleChanged', + args=[1L]) + + call_async(q, conn, 'RequestChannel', + tp_name_prefix + '.Channel.Type.RoomList', HANDLE_TYPE_NONE, + 0, True) + ret = q.expect('dbus-return', method='RequestChannel') + assert 'RoomListChannel' in ret.value[0] + + q.expect('dbus-signal', signal='NewChannels', + args=[[(tp_path_prefix + '/Connection/idle/irc/test_40localhost/RoomListChannel0', + { tp_name_prefix + u'.Channel.ChannelType': + tp_name_prefix + u'.Channel.Type.RoomList', + tp_name_prefix + u'.Channel.TargetHandle': 0, + tp_name_prefix + u'.Channel.TargetHandleType': 0})]]) + q.expect('dbus-signal', signal='NewChannel', + args=[tp_path_prefix + '/Connection/idle/irc/test_40localhost/RoomListChannel0', + tp_name_prefix + u'.Channel.Type.RoomList', 0, 0, 1]) + chan = bus.get_object(conn.bus_name, + tp_path_prefix + '/Connection/idle/irc/test_40localhost/RoomListChannel0') + list_chan = dbus.Interface(chan, tp_name_prefix + u'.Channel.Type.RoomList') + list_chan.ListRooms(); + q.expect('dbus-signal', signal='GotRooms', predicate=lambda x:check_rooms(x.args[0])) + + call_async(q, conn, 'Disconnect') + q.expect_many( + EventPattern('dbus-return', method='Disconnect'), + EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1])) + return True + +if __name__ == '__main__': + exec_test(test, protocol=RoomListServer) + |