summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2012-10-29 11:57:38 +0000
committerWill Thompson <will.thompson@collabora.co.uk>2012-10-29 11:57:38 +0000
commit35047ec5017492132307e184173890d3e416fbae (patch)
tree9f9ef63e6c4d7433195109e19f7fbdbfa1084978 /tests
parent79425a010af79070a6b93c25deb5690cc72daf87 (diff)
parent7b7f61a8dae3f8de7436378ef3ae569a5323fcef (diff)
Merge branch 'room-list'
Diffstat (limited to 'tests')
-rw-r--r--tests/twisted/Makefile.am2
-rw-r--r--tests/twisted/channels/room-list-channel.py80
-rw-r--r--tests/twisted/channels/room-list-multiple.py67
-rw-r--r--tests/twisted/constants.py1
4 files changed, 150 insertions, 0 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index da7e1e5..e750d12 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -15,6 +15,8 @@ TWISTED_TESTS = \
channels/requests-create.py \
channels/requests-muc.py \
channels/muc-channel-topic.py \
+ channels/room-list-channel.py \
+ channels/room-list-multiple.py \
messages/accept-invalid-nicks.py \
messages/contactinfo-request.py \
messages/invalid-utf8.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..7a7934f
--- /dev/null
+++ b/tests/twisted/channels/room-list-channel.py
@@ -0,0 +1,80 @@
+
+"""
+Test getting a room-list channel
+"""
+
+from idletest import exec_test, BaseIRCServer
+from servicetest import EventPattern, call_async, tp_name_prefix, tp_path_prefix, assertEquals
+import dbus
+import constants as cs
+
+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, 'CreateChannel',
+ { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_ROOM_LIST },
+ dbus_interface=cs.CONN_IFACE_REQUESTS)
+ ret = q.expect('dbus-return', method='CreateChannel')
+ path, properties = ret.value
+ assertEquals(cs.CHANNEL_TYPE_ROOM_LIST, properties[cs.CHANNEL_TYPE])
+
+ def looks_like_a_room_list(event):
+ channels, = event.args
+ if len(channels) != 1:
+ return False
+ path, props = channels[0]
+
+ return props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_ROOM_LIST and \
+ props[cs.TARGET_HANDLE_TYPE] == cs.HT_NONE and \
+ props[cs.TARGET_ID] == ''
+
+ e = q.expect('dbus-signal', signal='NewChannels',
+ predicate=looks_like_a_room_list)
+
+ chan = bus.get_object(conn.bus_name, path)
+ 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)
+
diff --git a/tests/twisted/channels/room-list-multiple.py b/tests/twisted/channels/room-list-multiple.py
new file mode 100644
index 0000000..568f4b4
--- /dev/null
+++ b/tests/twisted/channels/room-list-multiple.py
@@ -0,0 +1,67 @@
+
+"""
+Test getting multiple room-list channels. telepathy-idle internally only
+creates a single roomlist channel (since there's not really any reason to have
+more than one) and passes that channel out whenever somebody asks for it.
+
+This test just excercises the case where we've already created the channel and
+we just need to hand it out to the next requestor
+"""
+
+from idletest import exec_test
+from servicetest import EventPattern, call_async, assertEquals
+import constants as cs
+
+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])
+
+ # request a roomlist channel
+ call_async(q, conn, 'CreateChannel',
+ { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_ROOM_LIST },
+ dbus_interface=cs.CONN_IFACE_REQUESTS)
+ ret = q.expect('dbus-return', method='CreateChannel')
+ path, properties = ret.value
+ assertEquals(cs.CHANNEL_TYPE_ROOM_LIST, properties[cs.CHANNEL_TYPE])
+
+ # verify that a new channel was created and signalled
+ def looks_like_a_room_list(event):
+ channels, = event.args
+ if len(channels) != 1:
+ return False
+ path, props = channels[0]
+
+ return props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_ROOM_LIST and \
+ props[cs.TARGET_HANDLE_TYPE] == cs.HT_NONE and \
+ props[cs.TARGET_ID] == ''
+
+ e = q.expect('dbus-signal', signal='NewChannels',
+ predicate=looks_like_a_room_list)
+
+ # FIXME: this is pretty questionable.
+
+ # try to request another roomlist channel
+ call_async(q, conn, 'EnsureChannel',
+ { cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_ROOM_LIST },
+ dbus_interface=cs.CONN_IFACE_REQUESTS)
+ ret = q.expect('dbus-return', method='EnsureChannel')
+ yours, path2, properties2 = ret.value
+
+ # assert that it returns the same channel
+ assertEquals(path, path2)
+ assert not yours
+
+ call_async(q, conn, 'Disconnect')
+ q.expect_many(
+ EventPattern('dbus-return', method='Disconnect'),
+ EventPattern('dbus-signal', signal='ChannelClosed', args=[path]),
+ EventPattern('dbus-signal', signal='StatusChanged', args=[2, 1]))
+ return True
+
+if __name__ == '__main__':
+ exec_test(test)
+
diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py
index 5602985..eae149b 100644
--- a/tests/twisted/constants.py
+++ b/tests/twisted/constants.py
@@ -39,6 +39,7 @@ CHANNEL_TYPE_DBUS_TUBE = CHANNEL + ".Type.DBusTube"
CHANNEL_TYPE_STREAMED_MEDIA = CHANNEL + ".Type.StreamedMedia"
CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text"
CHANNEL_TYPE_FILE_TRANSFER = CHANNEL + ".Type.FileTransfer"
+CHANNEL_TYPE_ROOM_LIST = CHANNEL + ".Type.RoomList"
CHANNEL_TYPE_SERVER_AUTHENTICATION = \
CHANNEL + ".Type.ServerAuthentication.DRAFT"
CHANNEL_TYPE_SERVER_TLS_CONNECTION = \