[Telepathy-commits] [telepathy-idle/master] Add a very basic test for joining an IRC channel
Jonathon Jongsma
jonathon.jongsma at collabora.co.uk
Fri Feb 13 17:43:16 PST 2009
I'm not sure whether this test really has a lot of value, but it essentially
documents the current behavior
---
tests/twisted/Makefile.am | 1 +
tests/twisted/channels/join-muc-channel.py | 40 ++++++++++++++++++++++++++++
tests/twisted/idletest.py | 12 ++++++--
3 files changed, 50 insertions(+), 3 deletions(-)
create mode 100644 tests/twisted/channels/join-muc-channel.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 29271ee..2168c9c 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -3,6 +3,7 @@ TWISTED_TESTS = \
connect/connect-success-ssl.py \
connect/connect-fail.py \
connect/connect-fail-ssl.py \
+ channels/join-muc-channel.py \
$(NULL)
TESTS =
diff --git a/tests/twisted/channels/join-muc-channel.py b/tests/twisted/channels/join-muc-channel.py
new file mode 100644
index 0000000..126b59c
--- /dev/null
+++ b/tests/twisted/channels/join-muc-channel.py
@@ -0,0 +1,40 @@
+
+"""
+Test connecting to a IRC channel
+"""
+
+from idletest import exec_test
+from servicetest import EventPattern, call_async
+import dbus
+
+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])
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+ room_handles = conn.RequestHandles(2, ['#idletest'])
+ call_async(q, conn, 'RequestChannel', 'org.freedesktop.Telepathy.Channel.Type.Text', 2, room_handles[0], True)
+ q.expect('dbus-return', method='RequestChannel',
+ value=('/org/freedesktop/Telepathy/Connection/idle/irc/test_40localhost/MucChannel%d' % room_handles[0],))
+ q.expect('dbus-signal', signal='NewChannels',
+ args=[[('/org/freedesktop/Telepathy/Connection/idle/irc/test_40localhost/MucChannel%d' % room_handles[0],
+ { u'org.freedesktop.Telepathy.Channel.ChannelType':
+ u'org.freedesktop.Telepathy.Channel.Type.Text',
+ u'org.freedesktop.Telepathy.Channel.TargetHandle': room_handles[0],
+ u'org.freedesktop.Telepathy.Channel.TargetHandleType': 2L})]])
+ q.expect('dbus-signal', signal='NewChannel',
+ args=['/org/freedesktop/Telepathy/Connection/idle/irc/test_40localhost/MucChannel%d' % room_handles[0],
+ u'org.freedesktop.Telepathy.Channel.Type.Text', 2L, room_handles[0], 1])
+ q.expect('dbus-signal', signal='MembersChanged')
+ 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, timeout=10)
+
diff --git a/tests/twisted/idletest.py b/tests/twisted/idletest.py
index fe8a88e..8db3f5c 100644
--- a/tests/twisted/idletest.py
+++ b/tests/twisted/idletest.py
@@ -23,6 +23,10 @@ def make_disconnected_event():
event = make_irc_event('irc-disconnected', None)
return event
+def make_privmsg_event(recipient, msg):
+ event = make_irc_event('irc-privmsg', {'recipient':recipient, 'message':msg})
+ return event
+
class BaseIRCServer(irc.IRC):
def __init__(self, event_func):
self.event_func = event_func
@@ -48,8 +52,8 @@ class BaseIRCServer(irc.IRC):
print ("data received: %s" % (data,))
(prefix, command, args) = irc.parsemsg(data)
if command == 'PRIVMSG':
- self.event_func(make_privmsg_event(args))
-#handle 'login' handshake
+ self.event_func(make_privmsg_event(args[0], ' '.join(args[1:])))
+ #handle 'login' handshake
elif command == 'PASS':
self.passwd = args[0]
elif command == 'NICK':
@@ -59,7 +63,9 @@ class BaseIRCServer(irc.IRC):
if ((not self.require_pass) or (self.passwd is not None)) \
and (self.nick is not None and self.user is not None):
self.sendWelcome()
-
+ elif command == 'JOIN':
+ print ("Joined channel %s" % args[0])
+ self.sendMessage('JOIN', args[0], prefix=self.nick)
elif command == 'QUIT':
self.transport.loseConnection()
--
1.5.6.5
More information about the telepathy-commits
mailing list