diff options
author | Will Thompson <will.thompson@collabora.co.uk> | 2009-08-29 02:01:03 +0100 |
---|---|---|
committer | Will Thompson <will.thompson@collabora.co.uk> | 2009-08-29 02:51:03 +0100 |
commit | aa167c5c416023ef912c4db288264c2de68d1522 (patch) | |
tree | 759b6d9cc8dbde2751ce28d01004ae51373f3997 /tests | |
parent | 56bc2adff9f42d2e614e8f3eb8c50a5c54dacff8 (diff) |
Test Creating and Ensuring MUCs.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/Makefile.am | 1 | ||||
-rw-r--r-- | tests/twisted/channels/requests-muc.py | 105 | ||||
-rw-r--r-- | tests/twisted/idletest.py | 13 |
3 files changed, 118 insertions, 1 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 5b1d05d..a272f1c 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -8,6 +8,7 @@ TWISTED_TESTS = \ connect/invalid-nick.py \ channels/join-muc-channel.py \ channels/requests-create.py \ + channels/requests-muc.py \ messages/accept-invalid-nicks.py \ messages/message-order.py \ messages/leading-space.py \ diff --git a/tests/twisted/channels/requests-muc.py b/tests/twisted/channels/requests-muc.py new file mode 100644 index 0000000..a1191c2 --- /dev/null +++ b/tests/twisted/channels/requests-muc.py @@ -0,0 +1,105 @@ +""" +Test connecting to a IRC channel via the Requests interface +""" + +from idletest import exec_test, BaseIRCServer +from servicetest import EventPattern, call_async, sync_dbus, make_channel_proxy +import constants as cs +import dbus + +class DelayJoinServer(BaseIRCServer): + def handleJOIN(self, args): + # do nothing; wait for the test to call sendJoin(). + return + +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') + q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) + + self_handle = conn.GetSelfHandle() + + request = dbus.Dictionary({ + cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_TEXT, + cs.TARGET_HANDLE_TYPE: cs.HT_ROOM, + cs.TARGET_ID: '#idletest', + }, signature='sv') + + call_async(q, conn, 'CreateChannel', request, + dbus_interface=cs.CONN_IFACE_REQUESTS) + + # Idle should try to join the channel. + q.expect('stream-JOIN') + + # Meanwhile, in another application... + + call_async(q, conn, 'EnsureChannel', request, + dbus_interface=cs.CONN_IFACE_REQUESTS) + + sync_dbus(bus, q, conn) + + # Now the ircd responds: + stream.sendJoin('#idletest') + + cc, ec = q.expect_many( + EventPattern('dbus-return', method='CreateChannel'), + EventPattern('dbus-return', method='EnsureChannel'), + ) + nc = q.expect('dbus-signal', signal='NewChannels') + + path, props = cc.value + + assert props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TEXT + assert sorted(props[cs.INTERFACES]) == \ + sorted([cs.CHANNEL_IFACE_GROUP, + cs.CHANNEL_IFACE_PASSWORD, + cs.TP_AWKWARD_PROPERTIES, + ]) + assert props[cs.TARGET_HANDLE_TYPE] == cs.HT_ROOM + assert props[cs.TARGET_ID] == '#idletest' + assert props[cs.TARGET_HANDLE] == \ + conn.RequestHandles(cs.HT_ROOM, ['#idletest'])[0] + assert props[cs.REQUESTED] + assert props[cs.INITIATOR_HANDLE] == self_handle + assert props[cs.INITIATOR_ID] == \ + conn.InspectHandles(cs.HT_CONTACT, [self_handle])[0] + + ec_yours, ec_path, ec_props = ec.value + assert not ec_yours + assert ec_path == path + assert ec_props == props + + channels = nc.args[0] + assert len(channels) == 1 + nc_path, nc_props = channels[0] + assert nc_path == path + assert nc_props == props + + # And again? + ec_ = conn.EnsureChannel(request, + dbus_interface=cs.CONN_IFACE_REQUESTS) + assert ec.value == ec_ + + chans = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels', + dbus_interface=cs.PROPERTIES_IFACE) + assert len(chans) == 1 + assert chans[0] == (path, props) + + chan = make_channel_proxy(conn, path, 'Channel') + chan.Close() + + q.expect('stream-PART') + stream.sendPart('#idletest', stream.nick) + + q.expect('dbus-signal', signal='Closed') + + chans = conn.Get(cs.CONN_IFACE_REQUESTS, 'Channels', + dbus_interface=cs.PROPERTIES_IFACE) + assert len(chans) == 0 + +if __name__ == '__main__': + exec_test(test, protocol=DelayJoinServer) + diff --git a/tests/twisted/idletest.py b/tests/twisted/idletest.py index c716cc4..7a586ad 100644 --- a/tests/twisted/idletest.py +++ b/tests/twisted/idletest.py @@ -63,8 +63,19 @@ class BaseIRCServer(irc.IRC): def handleJOIN(self, args, prefix): room = args[0] + self.sendJoin(room, [self.nick]) + + def sendJoin(self, room, members=[]): + members.append(self.nick) + self.sendMessage('JOIN', room, prefix=self.nick) - self._sendNameReply(room, [self.nick]) + self._sendNameReply(room, members) + + def sendPart(self, room, nick, message=None): + if message is not None: + self.sendMessage('PART', room, message, prefix=nick) + else: + self.sendMessage('PART', room, prefix=nick) def _sendNameReply(self, room, members): #namereply |