From a7f057426578d93ae61d4dda25900c71384e218f Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Mon, 25 Apr 2011 22:49:45 +0300 Subject: [PATCH 4/4] Test to cover RequestContactInfo Fixes: https://bugs.freedesktop.org/34796 --- tests/twisted/Makefile.am | 1 + tests/twisted/messages/contactinfo-request.py | 68 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 deletions(-) create mode 100644 tests/twisted/messages/contactinfo-request.py diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 020e996..95c50e4 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -13,6 +13,7 @@ TWISTED_TESTS = \ channels/requests-muc.py \ channels/muc-channel-topic.py \ messages/accept-invalid-nicks.py \ + messages/contactinfo-request.py \ messages/messages-iface.py \ messages/message-order.py \ messages/leading-space.py \ diff --git a/tests/twisted/messages/contactinfo-request.py b/tests/twisted/messages/contactinfo-request.py new file mode 100644 index 0000000..dc8904c --- /dev/null +++ b/tests/twisted/messages/contactinfo-request.py @@ -0,0 +1,68 @@ + +""" +Test RequestContactInfo implementation +""" + +from idletest import exec_test +from servicetest import EventPattern, call_async +from constants import * +import dbus + +CHANNEL_NAMES = ['#idletest0', '#idletest1'] + +def validate_vcard(vcard): + channel_names = [] + for (name, parameters, value) in vcard: + if name == 'fn': + assert value[0] == 'Test User' + elif name == 'x-irc-channel': + channel_names.append(value[0]) + elif name == 'x-idle-time': + assert value[0] == '42' # fake value + elif name == 'nickname': + assert value[0] == 'test' + elif name == 'x-presence-type': + assert int(value[0]) == PRESENCE_AVAILABLE + elif name == 'x-presence-status-identifier': + assert value[0] == 'available' + assert channel_names == CHANNEL_NAMES + +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]) + + call_async(q, conn, 'GetSelfHandle') + event = q.expect('dbus-return', method='GetSelfHandle') + self_handle = event.value[0] + + room_handles = conn.RequestHandles(HT_ROOM, CHANNEL_NAMES) + for room_handle in room_handles: + call_async(q, conn, 'RequestChannel', CHANNEL_TYPE_TEXT, HT_ROOM, room_handle, True) + q.expect('dbus-return', method='RequestChannel') + q.expect('dbus-signal', signal='NewChannels') + + contact_info = dbus.Interface(conn, CONN_IFACE_CONTACT_INFO) + + call_async(q, contact_info, 'RequestContactInfo', self_handle) + event = q.expect('dbus-error', method='RequestContactInfo') + assert event.name == SERVICE_BUSY + + call_async(q, contact_info, 'RequestContactInfo', self_handle) + event = q.expect('dbus-return', method='RequestContactInfo') + vcard = event.value[0] + + validate_vcard(vcard) + + 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) -- 1.7.4.4